How to make the session variables in different files on the website exist in a session file
Source: Internet
Author: User
How to make the session variables in different files on the website exist in a session file. in the case of save_handler = files, I created two directories test1 and test2 under the root directory of the website, and put two test. phptest1/test. php & lt ;? Phpsession_start ()
Now I want to consider session. save_handler = files.
I created two directories test1 and test2 under the root directory of the website, and put two test. php directories respectively.
Test1/test. php
Session_start ();
$ _ SESSION ['other1'] = 'other12012 ';
Print_r ($ _ SESSION );
?>
Test2/test. php
Session_start ();
$ _ SESSION ['other2'] = 'other22012 ';
Print_r ($ _ SESSION );
?>
After these two files are run successively, the two cession variables exist in a session File: sess _. the content in the file is: other1 | s: 10: "other12012"; other2 | s: 10: "other22012 ";
But I found that sometimes the session on the same website does not have a session file,
For example, if I create a directory on the website and place a Forum program, the session of the Forum program always creates a session file instead of sharing a session file with other sessions.
I want all php programs on the website to share a session file...
------ Solution --------------------
Create a public include file head. php, which writes session information and is included in test1 and test2.
In this way, no matter how many levels of directories, you only need to include head. php.
------ Solution --------------------
A visitor corresponds to a server SESSION file and a SESSION-COOKIE for SESSION maintenance exist in the visitor's browser.
I don't know what you want?
Http://cn2.php.net/session_id
All pages use session_id to set the same session id to ensure that all visitors share the same SESSION-COOKIE (with a sesion id) and that they will access the same SESSION file on the server.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.