当我勾选复选框(cookie)并按登录时,它没有进入会员页面。它标头到索引页面(当前页面)。
但是当我勾选复选框(cookie)并再次按日志时,它的标题是会员页面
任何人都可以帮助我问题出在哪里?
<?PHP
session_start();
function loggedin(){
if(isset($_SESSION['log_email']) || isset($_COOKIE['log_email'])){
$loggedin=TRUE;
return $loggedin;
}
}
$log_email="";
if(loggedin()){
header("Location:member.php");}
if(isset($_POST['login'])){
$log_email=strtolower($_POST['log_email']);
$log_password=$_POST['log_password'];
if(isset($_POST['cookie'])){
$cookie=$_POST['cookie'];
}
if($log_email && $log_password){
$connect=mysql_connect("localhost", "root", "");
$database=mysql_select_db("phplogin", $connect);
$SQL=mysql_query("SELECT * FROM users WHERE email='$log_email'");
$numrows=mysql_num_rows($SQL);
if($numrows!=0){
while($result=mysql_fetch_assoc($SQL)){
$db_email=$result['email'];
$db_password=$result['password'];
$db_firstname=$result['firstname'];
$db_lastname=$result['lastname'];
}
if($log_email==$db_email && md5($log_password)==$db_password){
if($cookie){
setcookie("log_email", $log_email, time()+7200);
}
else{
$_SESSION['log_email']=$log_email;
header("location:member.php");
exit();
}
}
else{echo"wrong username or password";}
}
else{echo "Can't find the user";}
}
else{echo "Please enter email or password";}
}
?>
<html>
<body>
<div id="container">
<div id="logo"></div>
<div id="search"></div>
<div id="top_search"></div>
<div id="login">
<form action="index.php" method="POST">
<table>
<tr>
<td><lable id="td_1">Email</lable></td>
<td><lable id="td_1">Password</lable></td>
</tr>
<tr>
<td><input type="text" name="log_email" value="<?PHP echo $log_email; ?>" maxlength="50"/></td>
<td><input type="password" name="log_password" maxlength="25" /></td>
<td><input id="log_btn" type="submit" name="login" value="" /></td>
</tr>
<tr>
<td><div id="td_2"><input type="checkbox" name="cookie"/>Remember me</div></td>
<td><div id=td_2><a href="forgot_password.php">Forgot your password?</div></a></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>