Home  >  Article  >  Backend Development  >  Regarding the problem that php cannot obtain the session value

Regarding the problem that php cannot obtain the session value

藏色散人
藏色散人Original
2020-08-17 09:16:113159browse

The solution to the problem that php cannot obtain the session value: first create a folder named "session_temp"; then set its permissions to "writable"; and finally restart apache.

Regarding the problem that php cannot obtain the session value

Recommended: "PHP Video Tutorial"

I wrote a piece of code today and tested the session , but found that the written session value could not be obtained. After checking for a while, I finally found the problem:
My environment is windows7 apache2.22 php5.2.17
Specific session value code

page1.php
<?php
echo "what are you doing now?";
session_start();
$_SESSION[&#39;a&#39;] = &#39;wangzhong&#39;;
$_SESSION[&#39;b&#39;] = &#39;liyu&#39;;
?>
page2.php
<?php
echo "I am testing";
session_start();
echo $_SESSION[&#39;who&#39;].&#39;<br/>&#39;;
echo$_SESSION[&#39;hiswife&#39;],&#39;<br/>;
?>

The pages read by these two test sessions found that page2.php could not obtain the value saved in page1.php. What is the specific reason?
I checked the session configuration in apache, the details are as follows:

session

Session Support enabled
Registered save handlers files user
Registered serializer handlers php php_binary wddx
##DirectiveLocal ValueMaster Valuesession.auto_startOffOff##session.bug_compat_42session.bug_compat_warn##session.cache_expire180180session.cache_limiternocachenocachesession.cookie_domainOffOffsession.cookie_lifetime00session.cookie_path //session.cookie_secureOffOffsession.entropy_fileno value00session.gc_pisor10001000session.gc_maxlifetime1440144015##session.hash_function00no valueno valuefilessession.save_pathD:/php/session_tempD:/php/session_temp session.serialize_handlerphpphp##session.use_cookiessession.use_only_cookiessession .use_trans_sidThen I found that the sessions were all open. I checked the save path of the session and the result was The session_temp directory was not found in the php directory. It may be a problem here. I tried to create a folder with the same name and set it to be writable. Then I restarted apache and tested it again. This time I found that the session value could be read. arrive.
Off Off
On On
no value ##no value ##session.cookie_httponly
no value session. entropy_length
##session.gc_probability 1
session.hash_bits_per_character 5
##session.name PHPSESSID PHPSESSID
session.referer_check
##session.save_handler files
On On
Off Off
0 0
Really, this simple little problem also needs to be carefully investigated. I find that I have been a little impetuous recently. There is no problem if there is htmldom before the session_start() method, and it will not affect the reading of the session value. Similarly, if there is an echo output statement before the session_start() method, it will not affect the reading of the session value.

The above is the detailed content of Regarding the problem that php cannot obtain the session value. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn