2014-01-20 124 views
-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這純粹是爲了在目前的測試,所以如果我是顯示密碼以後我會改變不要緊。

+0

$ _SESSION ['pass']!= $ _ SESSION ['password']你也不能從db中獲取任何東西(按標題) – 2014-01-20 02:10:17

回答

0

正如Dagon指出的那樣,您設置了$_SESSION['pass'],但您試圖獲得$_SESSION['password']

作爲旁註,您似乎將數據庫中的密碼以純文本形式存儲,即使您現在只是進行測試,也應該使用而不是

+0

gosh,這是我見過的;) – 2014-01-20 02:12:01