0
這是我寫的一個登錄處理程序。用戶名和密碼都存在於我的數據庫中。當我嘗試登錄時,出現錯誤。PHP中出現錯誤登錄
這是我的base.php代碼:
?php
session_start();
$host="localhost"; // Host name
$username="root"; //Mysql username
$password=""; //Mysql password
$db_name="kuih"; // Database name
//Connect to server and select database.
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name") or die ("cannot select DB");
?>
這是我的index.php。
<?php include "base.php"; ?> //base.php
<?php
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['username']))
{
?>
<h1>Member Area</h1>
<pThanks for logging in! You are <b><?=$_SESSION['username']?></b> and your email address is <b><?=$_SESSION['email']?></b>.</p>
<?php
}
elseif(!empty($_POST['username']) && !empty($_POST['password']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = md5(mysql_real_escape_string($_POST['password']));
$checklogin = mysql_query("SELECT * FROM register WHERE username = '".$username."' AND password = '".$password."'");
if(mysql_num_rows($checklogin) == 1)
{
$row = mysql_fetch_array($checklogin);
$email = $row['email'];
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['LoggedIn'] = 1;
echo "<h1>Success</h1>";
echo "<p>We are now redirecting you to the member area.</p>";
echo "<meta http-equiv='refresh' content='=2;index.php' />";
}
else
{
echo "<h1>Error</h1>";
echo "<p>Sorry, your account could not be found. Please <a href=\"index.php\">click here to try again</a>.</p>";
}
}
else
{
?>
這是我的登錄表單代碼:
會員登錄
<p>Thanks for visiting! Please either login below, or <a href="register.php">click here to register</a>.</p>
<form method="post" action="index.php" name="loginform" id="loginform">
<fieldset>
<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
<input type="submit" name="login" id="login" value="Login" />
</fieldset>
</form>
<?php
}
?>
你覺得這個怎麼樣?誰能幫我?
添加'的print_r($ _ SESSION)''前回聲 「
錯誤
」'以獲取調試的詳細信息。 –**旁註**不要使用'mysql _ *()' - 它已被棄用。改爲使用'mysqli _ *()'或'PDO'。另外,如果您將它散列化,則不需要轉義密碼。對於SQL,MD5的輸出是安全的。 – 2013-11-05 03:33:17
嗨,我使用print_r($ _ SESSION),但仍然是相同的,帳戶無法找到.. –