我有:header.php,register.php,login.php和profile.php
当用户登录时,我使用header(Location:profile.php)在profile.php上重定向他
另外,在执行重定向之前,我设置了一个会话:
$_SESSION['logged']= $user_email;
使用此方法,我想对header.php做一个小技巧,例如:
if(($_SESSION['logged'] == true) {
echo "<a href="profile.php"> Logo </a>";
}
else {
echo "<a href="index.php"> Logo </a>";
}
不知何故,这不起作用。我想念什么吗?
您可以使用isset()函数控制会话变量
尝试下面的代码
session_start();
if(isset($_SESSION['logged'])){
header("location:profile.php");
}
else{
header("location:index.php");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句