0
下面的代碼應該檢查是否有效的會話存在或有效的cookie,如果這樣include_once file A.php
如果不是include_once login.php
。PHP是用戶會話/ cookie的有效的重定向錯誤
到目前爲止,login.php
和logout.php
正在正確執行(會話/ cookie)被創建和銷燬,但以下代碼仍未顯示正確的內容。
因爲這些代碼代表我看到了login.php
不管有效的會話或餅乾。
任何幫助將是偉大的。謝謝。
<?php
include_once '../accounts/dbc.php';
if (isset($_SESSION['user_id']) && isset($_SESSION['user_name']))
{
include_once 'A.php';
}
else if(isset($_COOKIE['user_id']) && isset($_COOKIE['user_key'])){
/* we double check cookie expiry time against stored in database */
$cookie_user_id = filter($_COOKIE['user_id']);
$rs_ctime = mysql_query("select `ckey`,`ctime` from `users` where `id` ='$cookie_user_id'") or die(mysql_error());
list($ckey,$ctime) = mysql_fetch_row($rs_ctime);
// coookie expiry
if((time() - $ctime) > 60*60*24*COOKIE_TIME_OUT) {
include_once '../login.php';
}
/* Security check with untrusted cookies - dont trust value stored in cookie.
/* We also do authentication check of the `ckey` stored in cookie matches that stored in database during login*/
if(!empty($ckey) && is_numeric($_COOKIE['user_id']) && isUserID($_COOKIE['user_name']) && $_COOKIE['user_key'] == sha1($ckey) ) {
session_regenerate_id(); //against session fixation attacks.
$_SESSION['user_id'] = $_COOKIE['user_id'];
$_SESSION['user_name'] = $_COOKIE['user_name'];
/* query user level from database instead of storing in cookies */
list($user_level) = mysql_fetch_row(mysql_query("select user_level from users where id='$_SESSION[user_id]'"));
$_SESSION['user_level'] = $user_level;
$_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']);
include_once 'A.php';
}
else {
include_once '../login.php';
}
} else {
include_once '../login.php';
}
?>
什麼是'COOKIE_TIME_OUT'和'$ ctime'?你能打印這兩個嗎? – Tushar 2013-04-03 22:17:06
@Tushar當你說打印你的意思是....(sr我有點在這裏我的深度) – 2013-04-03 22:20:14
@Tushar如果你想我有一個stacksoverflow聊天打開。無需填寫此區域。 http://chat.stackoverflow.com/rooms/info/27461/discussion-between-aventus-and-webmaster-alex-l – 2013-04-03 22:22:01