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 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序