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";
}
}
}
我从我的php脚本中删除了下面这行代码,它工作正常,但我不明白这段代码是如何解决问题的? $ labels = array(“username”=>“username”,“password”=>“password”); – sareeye
我也不明白,因为您不在给定脚本中的任何位置使用该数组。 – Trevor