1

So I have a login page on my website, which works perfectly on my computer, both Safari and Chrome, but on my iPhone, it does not work. I tried testing some code to see what is wrong, and sessions are not working in Safari. What I'm doing is once they log in, their session is $_SESSION['logged'] = true; and get redirected to the account page. I am accepting cookies. Any help is appreciated. Thanks

<?php
session_start();
$db = mysqli_connect(#,#,#,#);
if (isset($_POST['submit'])) {
    $username = mysqli_real_escape_string($db, $_POST['username']);
    $password = mysqli_real_escape_string($db, $_POST['password']);


    $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";

    $result = mysqli_query($db, $sql);

    if (mysqli_num_rows($result) == 1) {
    $_SESSION['username'] = $username;
     $_SESSION['logged'] = true;
     echo '<script type="text/javascript">
       window.location = "http://example.com/index.php?page=account"
       </script>';
} else {
    echo '<script>';
echo "Alert.render('Incorrect Username or Password.');";
echo '</script>';
}
}
?>
Francisco F.
  • 111
  • 1
  • 3
  • 14
  • This seems to be a similar question to the one you asked here http://stackoverflow.com/questions/41787597/sessions-not-working-in-safari How are you hosting this site and launching the site on your desktop versus your iphone? Do you have it hosted on a private DNS on an AWS, or or is it open for everyone to access, or is it being hosted on a local machine in your network? Also, can you var_dump() the full session details and the form details (You can keep password or hashes out of the content) for me, I may be able to help. – Dom DaFonte Feb 05 '17 at 05:52
  • @DomDaFonte I put the session details on my question. It is for public access, so it's not hosted on a local machine in my network. – Francisco F. Feb 05 '17 at 06:00
  • @DomDaFonte Also, if I do var_dump(), I get bool(true) when I disabled the window.location – Francisco F. Feb 05 '17 at 06:24
  • I see you use a JavaScript alert. If you go to settings ->safari there is a block pop-ups setting. Is this set appropriately? Also, can you add var_dump($_SESSION); right below your session_start(); to confirm whether you have an open session on iPhone? – Dom DaFonte Feb 05 '17 at 06:25
  • @DomDaFonte On my computer, I get this `array(2) { ["username"]=> string(8) "USERNAME" ["logged"]=> bool(true)}`. In my phone I get `array(0) {}` – Francisco F. Feb 05 '17 at 15:25
  • This sounds like a cookie policy issue with safari browser then. I think it's something along the lines of this article. If you have standard cookie policy on your phone I'd suggest you review and read this. When I get to a laptop I'll send you what I use to start my session as I have no issues cross browser. http://stackoverflow.com/questions/2733841/php-session-is-null-when-called-in-other-page-in-safari – Dom DaFonte Feb 05 '17 at 15:34

2 Answers2

1

Is your iPhone configured to accept cookies:?? Check the "Accept Cookies" setting under Safari in the Settings app.It might be disabled.

Tushar Sharma
  • 2,839
  • 1
  • 16
  • 38
0

It Solved for me Just by Turning of Prevent Cross Site Tracking option in Settings

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 28 '22 at 06:37