我正在尝试编写一个登录脚本,该脚本将设置一个会话变量,然后将用户重定向到另一个页面。会话变量在设置它的页面上显示良好,但在下一页上根本不显示。我已经剥离了我的主页,所以它所做的只是回显会话变量。
登录.php:
session_start();
if(isset($_POST['process_login'])){
include('php/db.php');
$query = mysql_query("SELECT USERS.USERNAME, USERS.PASSWORD FROM USERS") or die (mysql_error());
while ($result = mysql_fetch_array($query)){
if (strtoupper($_POST['username']) != $result['USERNAME'] || md5($_POST['password']) != $result['PASSWORD']){
echo "<center><font color=red>Incorrect username or password</font><center>";
}
else{
$_SESSION['username'] = $_POST['username'];
#echo $_SESSION['username'];
#printr ($_SESSION);
echo "<script> window.location = \"home.php\"; </script>";
}
//echo $result['username'];
}
}
主页.php
session_start();
echo $_SESSION['username'];