php脚本只允许一次登录,如果我注销我不能再次登录


php scrips allow one login only, if i logout I can not login again?

我有一个登录php脚本的问题。该脚本只允许我登录一次页面,一旦注销,我就不能再次登录了吗?从语法上看,它似乎很好,这是我的代码示例

   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";
                }

        }

    }

在注销脚本中,您需要清除会话和cookie变量。