我已经使用手机附带的“通用”浏览器在 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 - 解决这个问题有点复杂,假设您需要一个可用的永久标识符,这样用户就不必登录(生成您的自己的 session ID 加密 token ,该 token 用时间标识用户并设置 future 的到期时间 - 如果没有找到匹配的 session ID,则解密以获取记住我的值)。
C.
关于php - 移动浏览器无法登录我的网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2584155/