Home  >  Article  >  Backend Development  >  SESSION信息保存在哪个文件目录下以及能够用来保存什么类型的数据_php技巧

SESSION信息保存在哪个文件目录下以及能够用来保存什么类型的数据_php技巧

WBOY
WBOYOriginal
2016-05-17 09:10:401009browse
1.SESSION信息保存在哪?
复制代码 代码如下:

session_start();
$_SESSION['name']='marcofly';
?>

session默认是保存到c:\windows\temp目录下,但是通过修改php.ini中的session.save_path值可以改变session的保存路径。
如:session.save_path = "d:/wamp/tmp"
执行该代码后,就会在d:/wamp/tmp目录下,新增一个文件名为:sess_***的文件,打开之后,内容如下:name|s:8:"marcofly";
文件内容解释:
name:key
s:保存类型是字符串
8:字符串长度
marcofly:value
2.SESSION能够保存什么类型的数据呢?
如前一个例子所示,session能保存字符串,不仅如此,session还能保存整型(int),布尔型(bool),数组(array),而且,session还能保存对象
我们通过一个例子来简单的看下:
复制代码 代码如下:

session_start();
$_SESSION['name']='marcofly';//字符串
$_SESSION['int']='10';//整型
$_SESSION['bool']=True;//布尔型
$_SESSION['array']=array('name'=>'marcofly','age'=>'23');//数组
class test{
public $msg;
public function __construct(){
$this->msg="Hello World";
}
}
$obj=new test();
$_SESSION['obj']=$obj;//对象
?>

结果如下:
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";}
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