我在數據庫中有兩個用戶,當我嘗試登錄時,它只停留在索引頁上。如果一個用戶在數據庫中,您可以很好地登錄,但只有兩個用戶纔會重定向到索引頁面。這是什麼問題。PHP登錄腳本不能正常工作
<?php
include("connect.php");
$username = $_POST["username"];
$password = $_POST["password"];
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
echo $username;
echo $password;
if (empty($_POST['username']) || empty($_POST['password']))
{
//$_SESSION["login_error"] = "1";
echo 'error code 1';
header ('Location: ../index.php');
}
//$password = sha1($password);
$sql = "SELECT * FROM users";
$result = mysql_query($sql);
if (!$result) die('Invalid query: ' . mysql_error());
$userid = "";
while ($row3 = mysql_fetch_array($result, MYSQL_ASSOC))
{
if(($username == $row3["username"]) && ($password == $row3["password"]))
{
$userid = $row3["id"];
$_SESSION["userid"] = $userid;
//$online = mysql_query("UPDATE numbers SET online='1' WHERE id='".$userid."'")
//or die(mysql_error());
//$type = mysql_query("UPDATE numbers SET type='facetime' WHERE id='".$userid."'")
//or die(mysql_error());
echo $userid;
echo 'error code 2';
header ('Location: ../control_panel.php');
}
else
{
$userid = "";
$_SESSION["userid"] = "";
header ('Location: ../index.php');
echo 'error code 3';
}
//debug
//echo $password;
//$useridvar = $_SESSION["userid"];
//echo $useridvar;
}
if ($_SESSION["userid"]=="")
{
header ('Location: ../index.php');
echo 'error code 4';
}
//else
//{
// $userid = "";
// $_SESSION["userid"]= "";
// header ('Location: ../login.php');
//}
?>
任何關於如何使它更好的建議然後 – mintuz
編輯我的帖子,試試上面的代碼。 – technology
嘿哇感謝:D – mintuz