有沒有一種方法爲index.php頁面的第一次加載設置一個值?爲index.php設置一個值頁面
我想index.php它加載像這樣「index.php?subject = 1」當它加載第一次。 ,因爲這個值會隨着他們在網站中移動而改變,我不希望它成爲一個固定值。
有人sugested
if(empty($_SESSION['visited'])) {
//DO STUFF
$_SESSION['visited'] = true; }
我不能似乎得到的是與我的工作的功能。
find_selected_page()
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>
你有'session_start();'在那裏,對吧? –
在代碼之前你使用過session_start會話會是最好的嗎? –
在'if(empty($ _ SESSION ['visited'])之後設置'$ _SESSION ['subject'] = 1'){' – Fallen