谁能告诉我为什么没有设置这个会话变量?当登录详细信息正确时,优惠页面会将用户重定向回索引,就像未设置会话变量一样。
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
mysql_connect("localhost", "******", "******") or die("Could not connect.");
mysql_select_db("*******") or die("Could not find database.");
if(($username=='')||($password==''))
{
echo"<script type='text/javascript'>;
alert('Please check and re-enter details');
window.location = 'index.php';
</script>";
}
$qry="SELECT*FROM login WHERE username = '$username' and password = '$password'";
$result=mysql_query($qry);
if(mysql_num_rows($result)==0)
echo "<script type='text/javascript'>;
alert('The username you have entered does not exist in our database. Please check ad re-enter details.');
window.location = 'index.php';
</script>";
if(mysql_num_rows($result)> 0)
{
$_SESSION['username'] = $username;
header('location: offers.php');
}
?>
offer.php 代码
<?php
if ($_SESSION["username"]=="")
{
header ('Location: index.php');
}
?>