次のコードは、有効なセッションまたは有効な Cookie が存在するかどうか、存在しない場合はチェックする必要がありinclude_once file A.php
ますinclude_once login.php
。
これまでのところ、login.php
とlogout.php
は正しく実行されています (セッション/Cookie) が作成および破棄されていますが、次のコードはまだ適切なコンテンツを表示していません。
このコードの現状ではlogin.php
、有効なセッションまたは Cookie に関係なく が表示されます。
どんな助けでも素晴らしいでしょう。ありがとうございました。
<?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';
}
?>