0

谁能告诉我为什么没有设置这个会话变量?当登录详细信息正确时,优惠页面会将用户重定向回索引,就像未设置会话变量一样。

<?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');
}
?>
4

2 回答 2

2

您需要将其放在session_start();您的 offer.php 页面的顶部。

于 2013-02-27T14:45:49.710 回答
1

尝试添加:

session_start();

到offers.php的顶部

于 2013-02-27T14:45:51.833 回答