简体   繁体   中英

Trouble passing data with php session variables after changing webhost

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,

MC

I have exactly the same problem going from webhost to webhost - with the sessions information working on the same page - but lost when tranferring to the next page .I probably have less experience than you - and have no understanding of the hosts php.ini - but perhaps you could have a look at my question on SESSIONS not transferring information php5.5

you may see the problem

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM