移动浏览器无法登录我的网站

时间:2010-04-06 10:39:43

标签: php authentication mobile

我使用手机附带的“通用”浏览器在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测试我的网站(至少这是浏览器设置所说的)。

感谢

2 个答案:

答案 0 :(得分:2)

某些移动浏览器(黑莓想到的)不会处理以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,则解密以获得记住我的值。)

下进行。

答案 1 :(得分:0)

您使用的移动浏览器可能不支持Cookie,因此无法在Cookie中存储会话ID或任何其他信息。

您应该尝试在网址中传递会话ID,以便您的网站可以在所有移动浏览器中使用。这可以通过在PHP配置中将session.use_trans_sid设置为true来完成,例如ini_set('session.use_trans_sid', true);

W3C在Mobile Web Best Practices

中提供了一些关于cookie的良好信息
相关问题