Which file directory does SESSION information reside in and what types of data can it be used to store

  • 2020-05-17 04:55:53
  • OfStack

1. Where is the SESSION information stored?
 
<?php 
session_start(); 
$_SESSION['name']='marcofly'; 
?> 

By default, session is saved to c:\windows\temp, but the session.save_path value in php.ini can be changed to session.
session. save_path = "d:/wamp/tmp"
After executing this code, a new file named: sess_*** will be added in the d:/wamp/tmp directory. When opened, it will read: name|s:8:"marcofly";
Document description:
name: key
s: the save type is a string
8: string length
marcofly: value
2. What kind of data can SESSION store?
As shown in the previous example, session can hold strings. Not only that, session can hold integers (int), Boolean (bool), arrays (array), and session can hold objects
Let's take a look at a simple example:
 
<?php 
session_start(); 
$_SESSION['name']='marcofly';// string  
$_SESSION['int']='10';// The integer  
$_SESSION['bool']=True;// The Boolean  
$_SESSION['array']=array('name'=>'marcofly','age'=>'23');// An array of  
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";}

Related articles: