php中的会话有问题[关闭]
问题描述:
I have a session code here that i want to redirect the all users if the session username is not equal to administrator..but my code is not working..can anyone know whats the problem? Please
code here:
<?php
session_start();
if(isset($_SESSION['username'])!='administrator'){
header('Location: ../index.php');
}
?>
我在这里有会话代码,如果会话用户名不等于管理员,我想重定向所有用户。 但我的代码不能正常工作..谁能知道这个问题是什么? 请 p>
代码: p>
&lt;?php
session_start();
if(isset($ _ SESSION ['username'] )!=''管理员'){
header('Location:../ index.php');
nnn'n?&gt;
div> pre>
div>
答
The return value of isset will never equal 'administrator'. Try this:
if (!isset($_SESSION['username']) || ($_SESSION['username'] != 'administrator'))
答
isset will only return true or false. If you want to check that it exists AND the value is not "administrator", something like:
<?php
session_start();
if(!empty($_SESSION['username']) && $_SESSION['username'] !='administrator'){
header('Location: ../index.php');
}
?>