我用PHP登錄系統從http://tutorialzine.com/2009/10/cool-login-system-php-jquery/工作檢查會話狀態只給你一個快速的概述,相信教程建立以下列方式變量:PHP:在二級頁面
<?php
define('INCLUDE_CHECK',true);
require 'connect.php';
require 'functions.php';
// Those two files can be included only if INCLUDE_CHECK is defined
session_name('tzLogin');
// Starting the session
session_set_cookie_params(1*7*24*60*60);
// Making the cookie live for 1 weeks
session_start();
if($_SESSION['id'] && !isset($_COOKIE['tzRemember']) && !$_SESSION['rememberMe'])
..........
所以除了我無法將會話變量從「主登錄」頁面轉移到後續頁面(其中包含受限制的內容)之外,這一點非常好。下面是我打算在每一個受限制的內容頁面
<?php
session_name('tzLogin');
session_set_cookie_params(1*7*24*60*60);
session_start();
if($_SESSION['id']) <-- I believe I need more code here (incldue the cookie)
{
//If all is well, I want the script to proceed and display the HTML content below.
}
else
{
header("Location: MainLogin.html");
or die;
//redirects user to the main login page.
}
?>
正如你所看到的起點放置的基本代碼,我是一個新手總量,但任何幫助將不勝感激。截至目前,即使我已正確登錄,我的受限內容頁面也會繼續重定向到主頁。因此,我懷疑SESSION狀態未被結轉。再次感謝!
@YogeshSuthar在開始會話後,您不能更改cookie參數或會話名稱(除非您銷燬並重新啓動它) – dethtron5000