我有以下PHP代码用于检查我的index.php中的登录
<?php
session_start();
$con = mysqli_connect("***", "***", "***", "***");
$fbid_check=$_SESSION['loginid_session'];
$fbphoto_session=$_SESSION['loginphoto_session'];
$fbname_sql=mysqli_query($con, "SELECT fb_name FROM uni_users WHERE fb_id='$fbid_check' ");
$name_fetch=mysqli_fetch_array($fbname_sql, MYSQLI_ASSOC);
$fbname_session=$name_fetch['fb_name'];
if(isset($fbname_session))
{
header("location: http://www.uniwink.com/landing/profile.php");
}
mysqli_close($con);
?>
这将检查登录并重定向到profile.php,其中标题中包含以下PHP代码以检查登录
<?php
$con = mysqli_connect("****", "****", "****", "****");
session_start();
$fbid_check=$_SESSION['loginid_session'];
$fbphoto_session=$_SESSION['loginphoto_session'];
$fbname_sql=mysqli_query($con, "SELECT fb_name FROM uni_users WHERE fb_id='$fbid_check' ");
$name_fetch=mysqli_fetch_array($fbname_sql, MYSQLI_ASSOC);
$fbname_session=$name_fetch['fb_name'];
if(!isset($fbname_session))
{
header("location: http://www.uniwink.com/landing");
}
mysqli_close($con);
?>
我有以下logout.php,它来自profile.php
<?php
session_start();
unset($_SESSION['loginid_session']);
unset($fbname_session);
session_destroy();
header("location: http://www.uniwink.com/landing");
exit();
?>
问题是在注销后,它仍然进入profile.php。就像会话没有被破坏一样。事情是它一直工作到昨天,并突然发生。感谢
答案 0 :(得分:2)
尝试将session_start();
移到mysql连接上方。
变化
$con = mysqli_connect("****", "****", "****", "****");
session_start();
到
session_start();
$con = mysqli_connect("****", "****", "****", "****");
也使用isset with session
if (isset($_SESSION['loginid_session'])){
.....
}
答案 1 :(得分:1)
尝试在注销时添加以下内容;
$_SESSION = array();
if (ini_get("session.use_cookies"))
{
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
注意:这会破坏会话 - 而不仅仅是会话数据。
答案 2 :(得分:0)
检查会话。
if (isset($_SESSION['loginid_session']))
{
header("location: http://www.uniwink.com/landing/profile.php");
}
else
{
header("location: http://www.uniwink.com/landing");
}