PHP session 的有效范围设置成整个站点目录

demo.php

<?php
header('Content-Type: text/html; charset=utf-8');

@session_set_cookie_params(3600, "/", "onestopweb.iteye.com", false, TRUE);

//启动新会话或者重用现有会话
session_start();

//配置 Seeeion
$_SESSION['data'] = array('user'=>'chaoyi','website'=>'onestopweb.iteye.com');

//使用 Session
var_dump($_SESSION['data']);
echo '<br>SESSION ID:'.session_id();

//session_destroy();

aaa/demo.php

<?php
header('Content-Type: text/html; charset=utf-8');

@session_set_cookie_params(3600, "/", "onestopweb.iteye.com", false, TRUE);

//启动新会话或者重用现有会话
session_start();

//使用 Session
var_dump($_SESSION['data']);

echo '<br>SESSION ID:'.session_id();

效果图:

 

猜你喜欢

转载自onestopweb.iteye.com/blog/2409084