2011-07-11 26 views
1

我遇到登錄php腳本的問題。腳本允許我登錄到該頁面只有一次,一旦註銷,我不能再次登錄?我看它似乎罰款interms語法的,這裏是我的代碼php scrips只允許一次登錄,如果我註銷我不能再次登錄?

session_start(); 
    if(isset($_POST['submit']))//if the user is not logged in see if they have submited log  in data 
    { 
    $labels = array("username" =>"username", "password" =>"password"); 
    //connect to the database 
    $databaseconnect = mysql_connect($dbConnectParams['DBhost'], 
             $dbConnectParams['DBuser'], 
            $dbConnectParams['DBpassword']) or die("could not connect to database server."); 
            mysql_select_db($dbConnectParams['DBdatabase']) or die("could not connect to the database\n".mysql_error()); 
    /*collect user entered log-in data from the submited form*/ 
     $username = mysql_real_escape_string(trim($_POST['username'])); 
     $password = mysql_real_escape_string(trim($_POST['password'])); 
     if(!empty($username) && !empty($password)){ 
     /* 
     look up the user name and password in the database*/ 
     $query ="select username, password from customer where username ='$username' and password = sha1('$password')"; 
     $result = mysql_query($query) or die("could not execute select query on "); 
      if(mysql_num_rows($result)==1){ 
       /* 
       the log in is ok, username and password exist in database, 
       so set the username and password cookies and redirect to home page. 
       */ 
       $row = mysql_fetch_array($result); 
       $_SESSION['username'] = $row['username']; 
       $_SESSION['password'] = $row['password']; 

       setcookie('username', $row['username'], time()+ (60 * 60)); 
       setcookie('password', $row['password'], time()+ (60 * 60)); 
       header("Location:../index.php"); 

        } 

        } 



       elseif(empty($username) && empty($password)){ 
        //username and password incorrect , so set the error message 
        $error_msg .= 'sorry username and password required to log in'; 
        echo "$error_msg"; 

       mysql_close($databaseconnect); 
       } 
       else{ 
       //username and password incorrect , so set the error message 
        $error_msg .= 'sorry you must enter valid username and password to log in'; 
        echo "$error_msg"; 
       } 


     } 



    } 

回答

1

在你註銷腳本,你需要清除您的會話和餅乾瓦爾樣品。

+0

我從我的php腳本中刪除了下面這行代碼,它工作正常,但我不明白這段代碼是如何解決問題的? $ labels = array(「username」=>「username」,「password」=>「password」); – sareeye

+0

我也不明白,因爲您不在給定腳本中的任何位置使用該數組。 – Trevor

相關問題