Which file directory The session information is stored in and what type of data can be used to save _php tips

Source: Internet
Author: User
Where is the 1.SESSION information stored?
Copy Code code as follows:

<?php
Session_Start ();
$_session[' name ']= ' Marcofly ';
?>

Session default is saved to the C:\Windows\Temp directory, but by modifying the Session.save_path value in php.ini You can change the save path of the session.
such as: Session.save_path = "D:/wamp/tmp"
After executing the code, it will be in the D:/wamp/tmp directory, add a file named: sess_*** file, after opening, the contents are as follows: Name|s:8: "Marcofly";
File Content Explanation:
Name:key
S: Save type is a string
8: String length
Marcofly:value
What type of data can 2.SESSION hold?
As the previous example shows, sessions can hold strings, not only that, the session can also hold integers (int), Boolean (bool), arrays (array), and the session can save objects
Let's take a look at a simple example:
Copy Code code as follows:

<?php
Session_Start ();
$_session[' name ']= ' marcofly ';//String
$_session[' int ']= ' 10 ';//integral type
$_session[' bool ']=true;//boolean type
$_session[' array ']=array (' name ' => ' marcofly ', ' age ' => ' 23 ');//Array
Class test{
Public $msg;
Public Function __construct () {
$this->msg= "Hello World";
}
}
$obj =new test ();
$_session[' obj ']= $obj;//Object
?>

The results are as follows:
Name|s:8: "Marcofly";
Int|s:2: "10";
Bool|b:1;
Array|a:2:{s:4: "Name"; S:8: "Marcofly"; s:3: "Age"; S:2: "23";}
obj| O:4: "Test": 1:{s:3: "MSG"; s:11: "Hello World";}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.