I'm having a PHP website of version 5.4.45, while on logging in, it works as expected in desktop system and some mobile devices but in some mobile devices the login gets failed.
My Mobile Device information:
Application version: Chrome 73.0.3683.90
Operating System: Android 8.1.0; Moto G (5S) Plus Build OPSS28.65-36-9
Legal Information: Copyright 2019 Google Inc. All rights reserved
I tried the with the following solutions but I can't able to maintain the session - php session.use_trans_sid - PHP session lost after redirect - PHP session destroyed too soon on mobile browser(s)
I debugged the code in that device and then I found the session gets clears while on redirect. Before redirect I checked the session with var_dump($_SESSION)
it shows all the session values which I was set earlier after redirect header("Location: $redirectURL");
in the redirected page I check with var_dump($_SESSION)
it displays an empty array.
I also tried in PHP 7.1.X and 7.2.X, but it gives the same result - the session gets cleared.
My Sample Codes:
authenticate.php
session_start();
// temporarily I set the flag to true,
// actually it will set after database check
$login = true;
if ($login == true) {
// Session variable set
$_SESSION['userID'] = "user01";
$redirectURL = "profile.php";
header("Location: $redirectURL");
exit();
} else {
$redirectURL = "login.php";
header("Location: $redirectURL");
exit();
}
profile.php
session_start();
// Display empty string
echo($_SESSION['userID']);
I required to maintain the session while on header("Location: $redirectURL");