dongzouche9108 2017-05-01 19:21
浏览 222
已采纳

PHP Session_status()== PHP_SESSION_NONE有时显示会话未启动

I have had a good search on Google and on StackOverflow to see if anyone else has experienced this and I can't seem to find an answer.

Basically I'm in the late stages of developing my website on a local server and I've got one bug that I can't seem to squash.

Every so often when I load one of the pages I get a SESSION NOT STARTED message which comes from:

if (session_status() == PHP_SESSION_NONE) { die('SESSION NOT STARTED');
}//SESSION NEEDS TO START TO CHECK USERS

This is located in header.php, which is called on index.php after the body opens. (Just in-case the session doesn't start or I forget and errors get chucked everywhere.)

Right at the top of index.php (and every other page) session_start(); opens the session, so the session has definitely started... as so;

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
//Connect MYSQL
include 'mysql_conn.php';
include 'functions.php';
//START SESSION
session_start();

The message disappears if you refresh the page and I can't seem to re-create it by clearing cache / restarting browser / using private browsing or anything like that.

I was thinking maybe its setting it off when a "new" session is started maybe, unless I'm just doing it wrong? Its so rare that its hard to pinpoint what exactly is causing this.

Or should session_status be called before any form of output?

Thanks, any help appreciated

Edit: Running PHP 5.6.28

  • 写回答

1条回答 默认 最新

  • dqpu4988 2017-05-01 19:41
    关注

    Try to move the session_start() before including any file

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料