2011-02-07 141 views
0

這是我的,我嘗試作爲最後的努力最後一次嘗試:檢查登錄然後重定向到另一個頁面

的index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 

    <head> 
     <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
     <title>Customer Login</title> 
     <link href="stylesheet.css" rel="stylesheet" type="text/css" /> 
    </head> 

    <body> 
     <div class="wrapper"> 
      <div class="login"> 
       <form name="loginForm" action="loginCheck.php" method="post"> 
        <?php require("protect/serverInfo.php"); ?> 
         Email: <input type="text" name="Email" maxlength="35" /><br /> 
         Password: <input type="text" name="Password" maxlength="4" /><br /> 
        <input type="submit" name ="submit"/> 
       </form> 
      </div> 
     </div> 
    </body> 

</html> 

loginCheck.php

<?php 
     session_start(); 
     $_SESSION['email'] = $_POST['Email']; 
     $_SESSION['password'] = $_POST['Password']; 
     require("protect/serverInfo.php"); 
     $myusername=$_POST[Email]; 
     $mypassword=$_POST[Password]; 
     $result = mysql_query("SELECT * FROM Customers WHERE Email='$myusername' AND Password=$mypassword"); 
     $count=mysql_num_rows($result); 
     if($count==1){  
      header('Location: customer.php'); 
      exit(); 
     } 
     else{ 
      header('Location: index.php'); 
      exit(); 
     } 
?> 

客戶.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
<title>Untitled 1</title> 
<link href="stylesheet.css" rel="stylesheet" type="text/css" /> 
<?php 
    session_start(); 
    $myusername = $_SESSION['email']; 
    $mypassword = $_SESSION['password']; 
?> 
</head> 

<body> 
<?php 
echo"success"; 
?> 

</body> 

</html> 

我只需要一個非常簡單的方法來創建表單帖子,發佈信息將被檢查,如果正確,則重定向如果正確,並傳遞發佈數據。我一直在嘗試使用會話和重定向,但它不能很好地工作。什麼是最簡單的方法來實現這一點。目前我一直使用PHP來檢查來自MySQL數據庫的登錄信息。

+0

請問您可以發佈不正常的代碼嗎? – 2011-02-07 19:57:07

+0

我發佈了我的代碼。我知道位置不再是一個正確的網址我只是改變了它,所以網址不再被看到 – shinjuo 2011-02-07 20:03:34

回答

1

在頁面上做其他事情之前,您需要使用「session_start()」。

其他一些事情,我避免在一個頁面上存儲密碼..它只是看起來像一個安全問題。

您的登錄表單應根據從queury返回的mysql信息生成$ _SESSION數據,而不是用戶提交的表單信息。您需要檢查您的客戶數據庫,確保它們是實際的客戶。

此外,避免使用「header()」函數,尤其是在使用會話時。我通常在php中有一個「重定向」功能,可以做類似這樣的事情......

function redirect($url) { 
    echo "<script type='text'/javascript'>window.location='" . $url . "';</script>"; 
}