dscuu86620 2018-10-26 01:32
浏览 113
已采纳

PHP会话变量在Firefox 63.0,MacOS Mojave上的Safari 12.0和iOS 12.0.1上的Safari中丢失

The latest Firefox, version 63.0, on both Mac and Windows, has somehow broken the login I have built for the admininstrative backend of my ecommerce website. This was previously working fine. I use PHP.

On successful login with valid credentials a $_SESSION['admin_logged_in'] variable is set to TRUE and I am correctly logged in and redirected to a starting page. However when I then attempt to navigate to any other page within the admin site I am immediately logged out as if the session variable has suddenly been lost.

On every single page at the very beginning, including the starting page, I have an include with a short login check script which is as follows:

<?php
//start session
session_start() ;
//check user is logged in
if (($_SESSION['admin_logged_in'] !== TRUE) || (!isset($_SESSION['admin_logged_in']))) {
    header("location: /index.php") ;
    $_SESSION['admin_reason'] = "illegal" ;
    exit;
    }
?>

I may have thought this a bug with Firefox however recently I am also logged out, usually though after navigating through a couple of pages, by the latest version of Safari on iOS 12 and MacOS Mojave.

Currently working and no problems on Opera or Chrome (tested on Mac).

I have tried clearing the cache in Firefox and adjusting the privacy settings but no luck. I have spoken with my web hosts and they are not aware of any server side issues or changes.

But if there was a problem with the PHP code and session variables, since this is handled server side, presumably it would not work on any browser and also not worked previously?

Grateful for any suggestions.


I managed to solve this issue, please see my answer below.

  • 写回答

2条回答 默认 最新

  • dsdsm2016 2018-11-01 21:15
    关注

    I managed to solve this myself.

    To clarify, issue on Firefox version 63.0 on both Mac and Windows, Safari version 12.0 on MacOS Mojave and Safari on iOS 12.0.1. Other browsers tested, Chrome and Opera, were fine.

    I did some testing with a basic set of pages and found that in Firefox on all pages subsequent to any PHP session variable being set it was not available/did not exist. Safari usually lost it after navigating through a couple of pages.

    I then discovered the following page of an old post on the Mozilla forums reference favicons:

    https://bugzilla.mozilla.org/show_bug.cgi?id=263057

    I checked developer tools and discovered that these browsers, every time in the case of Firefox, and every few pages in the case of Safari, were requesting favicon.ico and getting a 404 response since I did not have one there. For some reason this was breaking the PHP session variables. I am not clear as to why.

    So the fix was simply to place a favicon.ico in the root directory of the website.

    Thank you for your comments.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害