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 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题