为index.php页面设置一个值

时间:2013-07-23 19:22:34

标签: php

有没有办法在第一次加载时为index.php页面设置一个值?

我希望index.php在第一次加载时加载“index.php?subject = 1”。 因为这个值会随着它们在网站中移动而改变,所以我不希望它成为固定值。

有人冒了一个人

 if(empty($_SESSION['visited'])) {
    //DO STUFF 
    $_SESSION['visited'] = true; }

我似乎无法使用我的功能。

find_selected_pa​​ge()

function find_selected_page () {
    global $current_subject;
    global $current_page;
    if (isset($_GET["subject"])) {
    $current_subject = find_subject_by_id ($_GET["subject"]);
    $current_page = find_default_post($current_subject ["id"]);
} elseif (isset($_GET["page"])) {
    $current_subject = null;
    $current_page = find_page_by_id ($_GET["page"]); 
} else {
    $current_page = null;
    $current_subject = null;
}
}

的index.php

<?php
    require_once($_SERVER['DOCUMENT_ROOT'].'/session/session.php');
    require_once($_SERVER['DOCUMENT_ROOT'].'/db/dbcon.php');
    require_once($_SERVER['DOCUMENT_ROOT'].'/inc/functions.php');
    $context = "public";
    find_selected_page ();
?>
<html>
  <head>
    <title>Home</title>   
<?php   include($_SERVER['DOCUMENT_ROOT'].'/inc/style.php'); ?>
<body>
<?php   include($_SERVER['DOCUMENT_ROOT'].'/inc/header.php'); ?>
<?php   include($_SERVER['DOCUMENT_ROOT'].'/inc/nav_ribbon.php');?>
    <div id="p2dbg">
        <div id="p2dcontent">
            <div class="p2dcontent">
        <h1><?php echo htmlentities($current_subject ["menu_name"]); ?></h1><br />
                <?php if ($current_page) { ?>
                        <p><?php echo nl2br($current_page ["content"]); ?></p><br />
                        <?php } else { ?>
                            This page does not exist! please slect a page from the menu.
                        <?php } ?>                      
            </div>
        </div>
<?php   include($_SERVER['DOCUMENT_ROOT'].'/inc/footer.php'); ?>
    </div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

如果未传递值,则不要将所有内容都设置为null,而是假设默认值为:

// Set this to the value you want as your default
define("DEFAULTSUBJECT",1);
function find_selected_page () {
    global $current_subject;
    global $current_page;
    if (isset($_GET["subject"])) {
        $current_subject = find_subject_by_id ($_GET["subject"]);
        $current_page = find_default_post($current_subject ["id"]);
    } elseif (isset($_GET["page"])) {
        $current_subject = null;
        $current_page = find_page_by_id ($_GET["page"]); 
    } else {
        $current_subject = find_subject_by_id (DEFAULTSUBJECT);
        $current_page = find_default_post($current_subject ["id"]);
    }
}