的login.php
if(isset($_POST["submit"])){
if(!empty($_POST['user']) && !empty($_POST['pass'])) {
$user=$_POST['user'];
$pass=$_POST['pass'];
$con=mysql_connect('localhost','Haha I almost forgot to take this stuff out.','Whoops. That wouldve been bad.') or die(mysql_error());
mysql_select_db('Jesus. I almost forgot this one too!') or die("cannot select DB");
$query=mysql_query("SELECT * FROM login WHERE username='".$user."' AND password='".$pass."'");
$numrows=mysql_num_rows($query);
if($numrows!=0)
{
while($row=mysql_fetch_assoc($query))
{
$dbusername=$row['username'];
$dbpassword=$row['password'];
}
if($user == $dbusername && $pass == $dbpassword)
{
session_start();
$_SESSION['sess_user']=$user;
/* Redirect browser */
header("Location: member.php");
}
} else {
echo "Invalid username or password!";
}
} else {
echo "All fields are required!";
}
}
我已经成功创建了一个帐户(我可以在我的数据库中看到它),但是当我登录时,只是将我重新定向到登录页面。
如果我手动指向member.php页面,它工作正常(我可以看到我已经登录并且会话已启动),但是如果我只是尝试登录它,则永远不会重定向我。
我确定它很简单,我只是错过了,但你可以帮助我吗?
(对于我使用mysql而不是mysqli,我大吼大叫我只是测试K?我最终会修复它D:)
答案 0 :(得分:0)
我可能读错了,但看起来你有一个额外的支架
header("Location: member.php");
}
}
答案 1 :(得分:0)
查找...
if($user == $dbusername && $pass == $dbpassword)
{
session_start();
$_SESSION['sess_user']=$user;
/* Redirect browser */
header("Location: member.php");
}
改为......
if($user == $dbusername && $pass == $dbpassword)
{
session_start();
$_SESSION['sess_user']= $dbusername;
session_write_close();
/* Redirect browser */
header('Location: member.php');
die();
}
此外,您可能希望使用mysql_free_result()和mysql_close()。