-2
我有一個系統,用戶根據他們的詳細信息是否與存儲在我的數據庫中的內容相匹配來登錄。顯示關於數據庫用戶的詳細信息
循環訪問數據庫並檢索記錄的代碼。
<?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("users_db") or die(mysql_error());
//checks cookies to make sure they are logged in
if(isset($_COOKIE['username']))
{
$username = $_COOKIE['username'];
$pass = $_COOKIE['pass'];
$check = mysql_query("SELECT * FROM users WHERE user_name = '$username'")or die(mysql_error());
while($info = mysql_fetch_array($check))
{
$username = $row['user_name'];
$email = $row['user_email'];
}
//if the cookie has the wrong password, they are taken to the login page
?>
顯示詳細信息的代碼。
<form action="profile.php" method="GET">
<p>
<label for="your-name">Username</label> <?php echo $_SESSION['username']; ?>
</p>
<p>
<label for="your-name">Password</label> <?php echo $_SESSION['password']; ?>
</p>
</form>
這是login.php中創建會話變量的代碼。
<?php
mysql_connect("localhost","root","");
mysql_select_db("users_db");
if(isset($_POST['login'])){
$password = $_POST['pass'];
$username = $_POST['username'];
$check_user = "select * from users where user_pass ='$password' AND user_name ='$username'";
$run = mysql_query($check_user);
if(mysql_num_rows($run)>0){
$_SESSION['username']=$username;
$_SESSION['pass']=$password;
//$pass = $_COOKIE['pass'];
echo "<script>window.open('home.php','_self')</script>";
}
else {
echo "<script>alert('Username or password is incorrect!')</script>";
}
}
?>
我可以顯示用戶名沒有問題,因爲某些原因,但是密碼無法顯示IE這純粹是爲了在目前的測試,所以如果我是顯示密碼以後我會改變不要緊。
$ _SESSION ['pass']!= $ _ SESSION ['password']你也不能從db中獲取任何東西(按標題) – 2014-01-20 02:10:17