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条)

报告相同问题?

悬赏问题

  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错