MyHall.php
<?php
if(isset($_GET['PHPSESSID'])){
session_id($_GET['PHPSESSID']);
}
//session在启动的时候会判断一下是否设置了sessionid
//如果设置了,就不会再产生新的,不设置会产生。
session_start();
//获取sessionid
$sid=session_id();
//购物大厅
echo "<h1>欢迎购买</h1>";
echo "<a href='ShopProcess.php?bookid=sn001&bookname=天龙八部&PHPSESSID=$sid'>天龙八部</a><br/>";
echo "<a href='ShopProcess.php?bookid=sn002&bookname=红楼梦&PHPSESSID=$sid'>红楼梦</a><br/>";
echo "<a href='ShopProcess.php?bookid=sn003&bookname=西游记&PHPSESSID=$sid'>西游记</a><br/>";
echo "<a href='ShopProcess.php?bookid=sn004&bookname=聊斋&PHPSESSID=$sid'>聊斋</a><br/>";
echo "<hr/>";
echo "<a href='ShowCart.php?PHPSESSID=$sid'>查看购买到的商品列表</a>";
?>
ShowProcess.php
<?php
//接收用户购买请求,并把书保存到session中。
$bookid=$_GET['bookid'];
$bookname=$_GET['bookname'];
//防止cookie禁用,所以不能创建session
if(isset($_GET['PHPSESSID'])){
session_id($_GET['PHPSESSID']);
}
$sid=session_id();
//保存到session中
//初始化session,就会在默认的目录中创建一个session文件
session_start();
$_SESSION[$bookid]=$bookname;
echo "<br/>购买商品成功!";
echo "<br/><a href='MyHall.php?PHPSESSID=$sid'>返回购物大厅继续购买</a>";
?>
ShowCart.php
<?php
echo "<h1>购物车商品有</h1>";
//防止cookie禁用,所以不能创建session
if(isset($_GET['PHPSESSID'])){
session_id($_GET['PHPSESSID']);
}
$sid=session_id();
//保存到session中
//初始化session,就会在默认的目录中创建一个session文件
session_start();
foreach($_SESSION as $key=>$val){
echo "<br/>书号--$key 书名--$val";
}
echo "<br/><a href='MyHall.php?PHPSESSID=$sid'>返回购物大厅继续购买</a>";
?>