php脚本只允许一次登录,如果我退出,我不能再次登录?
我在登录php脚本时遇到问题。脚本只允许我登录一次页面,一旦注销,我就不能再次登录了?从语法的角度来看,这似乎很好,下面是我的代码示例php脚本只允许一次登录,如果我退出,我不能再次登录?,php,scripting,login,logout,Php,Scripting,Login,Logout,我在登录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", "p
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变量。在您的注销脚本中,您需要清除会话和cookie变量。我从php脚本中删除了以下代码行,这行代码正常工作,但我不明白此代码是如何解决问题的$标签=数组(“用户名”=>“用户名”,“密码”=>“密码”);我也不明白这一点,因为在给定的脚本中,您没有在任何地方使用该数组。我从php脚本中删除了下面一行代码,并且它起了作用,但我不明白这段代码是如何解决问题的$标签=数组(“用户名”=>“用户名”,“密码”=>“密码”);我也不明白这一点,因为在给定脚本的任何地方都没有使用该数组。