【发布时间】:2011-05-02 15:27:36
【问题描述】:
感谢您的回复。我已经更新了我的 PHP 会话代码。
我有一个 (HTTPS)-login.php,它仍然是 HTTPS,即一旦用户登录到帐户仪表板。现在的问题是说用户在登录仪表板时单击(HTTP)-about-us.php 页面,会话没有通过 HTTP 传输,因为我有 session.cookie_secure=1,这很好用户似乎已注销。但是,当用户返回仪表板页面时,他是否也会在 HTTPS 上注销?
我相信我遗漏了导致此问题的某些内容。这是我的代码:
这是 PHP 头文件需要()来启动会话,即在 login.php 页面上:
session_start();
session_regenerate_id(true); /*avoid session fixation attempt*/
/*Create and check how long session has been started (over 5 mins) regenerate id - avoid session hijack*/
if(!isset($_SESSION['CREATED']))
{
$_SESSION['CREATED'] = time();/*time created session, ie from login/contact advertiser/email_confirm only ways for new session to start*/
}
elseif(time() - $_SESSION['CREATED'] > 300)
{
/*session started more than 5 mins(300 secs) ago*/
session_regenerate_id(true); /*change session ID for the current session and invalidate old session ID*/
$_SESSION['CREATED'] = time(); /*update creation time*/
}
/*Check if user is logged in*/
if(!isset($_SESSION['loggedin']))
{
$_SESSION['loggedin']=1;/*used to track if user is logged in on pages*/
}
/*if return false browser supports standard ob_start();*/
if(ob_start("ob_gzhandler")){ob_start();}
这是在每个页面上都需要()的 PHP 头文件,以检查会话是否已经启动:
session_start();
$session_errors=0;/* if>0 user not logged in*/
/*check if session is already initiated*/
if(isset($_SESSION['CREATED']))
{
if(time() - $_SESSION['CREATED'] > 300)
{
/*session started more than 5 mins(300 secs) ago*/
session_regenerate_id(true); /*change session ID for the current session and invalidate old session ID*/
$_SESSION['CREATED'] = time(); /*update creation time*/
}
}
elseif(!isset($_SESSION['CREATED'])){$session_errors++;}/*user not logged in*/
/*Check if user is logged in*/
if(!isset($_SESSION['loggedin'])){$session_errors++;}/*user not logged in*/
if(ob_start("ob_gzhandler")){ob_start();}
如果有任何用途,这是在非敏感页面(例如 about-us.php)上打开 HTTPS 的代码
if ($_SERVER['SERVER_PORT']!=80)
{
$url = "http://". $_SERVER['SERVER_NAME'] . ":80".$_SERVER['REQUEST_URI'];
header("Location: $url");
}
再次感谢大家的帮助,daza166
【问题讨论】: