douchu2823 2014-12-09 20:03
浏览 30

为什么我的会话无法正常工作?

My session does fails to resume when opening another file

I have 2 pages, test.php and test2.php. Each of my files are listed below.

test.php:

<?php
  session_save_path('sessBin');
  session_id('mySessionID');
  session_start();
  $_SESSION[1]="yo";
  echo $_SESSION[1];
?>
<a href="test2.php">go to test 2</a>

test2.php:

<?php
  session_save_path('sessBin');
  session_id('mySessionID');
  session_start();
  echo $_SESSION[1];
  echo "bleh";
?>

The first page returns:

"yo" <a href="test2.php">go to test 2</a>

however, when clicking on the link to go to test2.php, only this returns:

"bleh"

I did some research to find that cookies must be enabled. Well, they are... So what is wrong?

NOTE: (A discovery from afterwards)

I did notice that there were several files(including sess_mySessionID) in sessBin so the session is stored. However, the files are empty and the session does not seem to resume

  • 写回答

3条回答 默认 最新

  • doulei3488 2014-12-09 20:15
    关注

    session_start needs to be defined at the top of every page, right after the opening php tag, on every page where the session data is expected to exist. You must do this before addressing any other session function or variable.

    ** Update to Answer Based On Your Comments **

    check for white space before the opening php tag in test2.php. Also, enable error reporting. You might be sending something out before the session call that is causing session_start() to fail.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)