doubi1931 2015-10-26 19:37
浏览 56
已采纳

更改webhost后,使用php会话变量传递数据时出现问题

I developed a basic web application as an exercise to learn php. I completed the application on a first webhost (with php 5.4.38 installed) but had to switch to another one afterwards (with php 5.5.30 installed). The code was working fine with the first webhost but once I switched to the other one things fell apart because every time the code tried to retrieve data from a session variable previously set in another file the value returned was empty.

In particular, I am able to retrieve data from the session variable in the html file that is included just after the php file where the session was set. However, once I try to navigate through the site from there, the session variable is empty.

I checked the php.ini of both webhosts and I found some differences in the session variables configuration. I looked on the web for solutions and tried to implement them but, so far, unsuccessfully. I tried to modify the session's config in the second php.ini but that didn't work either.

As you can see (from the two hyperlinks provided below), the "Registered save handlers" are partially different: on the second host the "memcache" handler is missing (I read on the internet about the possibility to store sessions either in memcache or in a database but to be honest it is way too technical for me given my current knowledge of php).

The "Registered serializer handlers" are also partially different, in the first host's config they are "php php_binary wddx" while in the second one's they are "php_serialize php php_binary wddx".

Besides from the save handlers, the second host also has some "entropy" settings, which the first one doesn't have. Also, the first host has the "force_path" setting set to "1" while the setting doesn't appear in the second host's file. Also, the first host has "gc_probability" set to "0" while the second one has it set to "1". Furthermore, the first host has no "use_strict_mode" setting while the second one has it set to "Off". Finally, the first host has "use_trans_sid" setting set to "1" while the second host has it set to "0".

My best guess is that the problem lies in the absence of "memcache" has a save handler in the second webhost's php.ini file, however, I have no clue about how to fix it.

Please find attached the relevant portion of the two php.ini, if you need the rest of the php.ini or more info let me know.

First host php.ini config Second host php.ini config

Edit: I tried to comment out the session entropy settings on the second php.ini but this did not solve the problem.

Thanks in advance,

M.C.

  • 写回答

2条回答 默认 最新

  • 普通网友 2015-11-04 12:34
    关注

    Fixed it. While in error mode I saw this "Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at...)". So I basically removed every "session_start();" from my code after the first one and the problem disappeared. I still have no idea of which part of the php.ini configuration caused the problem though.

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

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法