我使用手机附带的“通用”浏览器在2个手机型号上测试了我的网站,但遗憾的是,每当我尝试登录时,它都会将我返回到我的索引页面.
这是我的登录代码
<form name='login' method='POST' action='authentication.php'>
<table border=0 cellpadding=2>
<tr><td>Login:</td><td></td></tr>
<tr><td>E-mail: </td><td><input type=text name='email' id='email' size=20 maxlength="200"></td></tr>
<tr><td>Password: </td><td><input type=password name='password' id='password' size=20 maxlength="100"></td></tr>
<tr><td></td><td><input type=submit value='Login'></td></tr>
</table></form>
这是authentication.php(片段)
$currentUserEmail = $_POST["email"];
$currentUserPwd = md5($_POST["password"]);
$stmt = $dbi->prepare("select status from users where email=? and pwd=?");
$stmt->bind_param('ss', $currentUserEmail,$currentUserPwd);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$isUserAvailable = mysqli_stmt_num_rows($stmt);
$stmt->bind_result($getUserStatus);
$stmt->execute() or die (mysqli_error());
$stmt->store_result();
$stmt->fetch();
$stmt->close();
if($isUserAvailable > 0){
if ($getUserStatus == "PENDING") {
$userIsLoggedIn = "NO";
$registeredUser = "NO";
unset($userIsLoggedIn);
setcookie("currentMobileUserName", "", time()-3600);
setcookie("currentMobileUserEmail", "", time()-3600);
setcookie("currentMobileSessionID", "", time()-3600);
setcookie("currentMobileUID", "", time()-3600);
header('Location: '.$config['MOBILE_URL'].'/index.php?error=2&email='.$currentUserEmail);
}elseif (($getUserStatus == "ACTIVE") || ($getUserStatus == "active")){ //means successfully logged in
//set the cookie
setcookie("currentMobileUserName", $currentUserName, $expire);
setcookie("currentMobileUserEmail", $currentUserEmail, $expire);
setcookie("currentMobileSessionID", $getGeneratedMobileUSID, $expire);
setcookie("currentMobileUID", $currentUID, $expire);
$userIsLoggedIn = "YES";
$registeredUser = "YES";
$result = $stmt->execute() or die (mysqli_error($dbi));
if ($caller == "indexLoginForm"){
header('Location: '.$config['MOBILE_URL'].'/home.php');
}else{
header('Location: '.$config['MOBILE_URL'].'/home.php');
}
}
}else{
$userIsLoggedIn = "NO";
$registeredUser = "NO";
unset($userIsLoggedIn);
setcookie("currentMobileUserName", "", time()-3600);
setcookie("currentMobileUserEmail", "", time()-3600);
setcookie("currentMobileSessionID", "", time()-3600);
setcookie("currentMobileUID", "", time()-3600);
header('Location: '.$config['MOBILE_URL'].'/index.php?error=1');
}
我可以访问我的移动网站的唯一方法是使用opera mini.仅供参考,两种“通用浏览器”我都使用支持cookie测试我的网站(至少这是浏览器设置所说的).
谢谢
最佳答案 一些移动浏览器(黑莓想到的)不会处理以2xx响应发送的任何cookie – 您正在使用302重定向进行响应.
试试这个:
setcookie("currentMobileUserName", $currentUserName, $expire);
setcookie("currentMobileUserEmail", $currentUserEmail, $expire);
setcookie("currentMobileSessionID", $getGeneratedMobileUSID, $expire);
setcookie("currentMobileUID", $currentUID, $expire);
$userIsLoggedIn = "YES";
$registeredUser = "YES";
... // some WML/HTML markup...
print "You are logged in. Click <a href='"
. $config['MOBILE_URL']. "/home.php'>here</a> to continue.";
此外,一些旧设备不喜欢每个站点保存多个cookie – 解决这个问题有点复杂,假设您需要一个持久标识符,因此用户无需登录(生成您自己的会话ID)加密用时间标识用户的令牌并设置将来的到期时间 – 如果找不到匹配的会话ID,则解密以获得记住我的值.
C.