2010-04-06 87 views
4

我已经使用手机随附的'通用'浏览器在两款手机型号上测试过我的网站,但不幸的是,每次我尝试登录时,它都会将我退回到我的索引页面。移动浏览器'无法登录我的网站

,这里是我的登录代码

<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(至少这是浏览器设置说)。

感谢

+0

您发布的代码并不真正相关,是吗?你在哪里管理会议? – 2010-04-06 10:41:05

+1

我不知道PHP,但不会这行“setcookie(”currentMobileSessionID“,”“,time() - 3600);”将Cookie的到期时间设置为过去一小时?不应该是setcookie(“currentMobileSessionID”,“”,time()+ 3600); ???? – andrewWinn 2010-04-06 11:42:14

+0

对不起,代码是不完整的,并忘记告诉我的手机网站驻留在一个子域。因此我只是添加路径“/”来设置cookie,从 setcookie(“currentMobileUserName”,$ currentUserName,$ expire); 到 setcookie(“currentMobileUserName”,$ currentUserName,$ expire,“/”); 现在它在大多数手机的浏览器上运行良好:D – imin 2010-04-13 04:21:03

回答

0

也许你正在使用不支持Cookie,因此移动浏览器将无法在会话ID存储在cookie或任何其他信息为这一问题。

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

W3C有关于cookies在他们的Mobile Web Best Practices

+0

非常感谢..我想我会使用会话来代替.. – imin 2010-04-13 04:21:38

+0

如果您使用会话,会话ID会记录在Cookie中,您仍然会遇到问题,有些手机不支持cookies。只有在URL中有会话ID才能使用。 – 2010-04-13 12:24:00

+0

omg ..这是相当麻烦的是不是:D ...非常感谢提醒 – imin 2010-04-28 07:25:58

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匹配,解密以获得记住我的值)。

C.

+0

嗯非常感谢信息..这让我觉得我真的应该使用会议,而不是 – imin 2010-04-13 04:23:08