Mobile browsers cannot access my site

I tested my site on two phone models using the β€œcommon” browser that came with the phone, but, unfortunately, every time I tried to log in, it will return me back to my index page.

here is my login code

<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> 

and here is authentic.php (snippet)

 $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'); } 

The only way to access the mobile site is to use opera mini. Just FYI, as "shared browsers", I tested my website with cookie support (at least that's what the browser settings said).

thanks

+4
source share
2 answers

Some mobile browsers (Blackberries spring) do not process cookies sent by anything other than a 2xx response - you are responding to a 302 redirect.

Try the following:

 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."; 

In addition, some older devices do not like to store more than one cookie for each site. The solution to this question is somewhat complicated if you want a constant identifier to be available, so the user does not need to register (generate a custom session identifier that encrypts a token that identifies the user over time and sets the expiration time in the future - if the session identifier is not found, decrypt to get the value "remember me").

FROM.

+2
source

It is likely that the mobile browsers you use do not support cookies and therefore cannot store the session ID in a cookie or any other information.

Instead, try passing the session ID to the URL so that your site works in all mobile browsers. This can be done by setting session.use_trans_sid to true in your PHP configuration, for example. ini_set('session.use_trans_sid', true);

W3C has good cookie information in Mobile Website Guidelines

0
source

Source: https://habr.com/ru/post/1306106/


All Articles