Home  >  Article  >  Backend Development  >  登录页面Session的有关问题

登录页面Session的有关问题

WBOY
WBOYOriginal
2016-06-13 13:22:44838browse

登录页面Session的问题
大家好,我又来了。

我的页面是这样写的:
session_start();
if($_SESSION['Admin'] == '' || $_SESSION['ID'] == ''){
echo '<script>';<br /> echo 'parent.location.href="Login.php";';<br /> echo '</script>';
}
------------------------------------------------------
现在的问题是一打开页面,它就老是提示错误,没有Session['Admin']变量。
虽然页面还是会继续执行,但是出错了感觉总是不好的。
除了用@来抑制错误,大家都有什么好方法吗。

------解决方案--------------------
if(isset($_SESSION['Admin']) && isset($_SESSION['ID'])){
代码.....
}else{
echo '<script>';<br />echo 'parent.location.href="Login.php";';<br />echo '</script>';
exit;
}
------解决方案--------------------
isset判断是否被赋值过,这和js里undefined是一样的道理。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn