从会话变量看会话机制
看三个小例子:
session1.php
Code
<?php
session_start();
$_SESSION['sess_var'] = 'hello world';
echo $_SESSION['sess_var'].'<br />';
?>
<a href="session2.php">下一页</a>
session2.php
Code
<?php
$svar = $_SESSION['sess_var'];
if (!isset($svar)) {
session_start();
echo 'session start<br />';
$svar = $_SESSION['sess_var'];
if (!isset($svar))
echo 'var not set'.'<br />';
else
echo $svar.'<br />';
}
else {
echo $svar.'<br />';
}
unset($_SESSION['sess_var']);
echo 'have unsetted'.'<br />';
?>
<a href="session1.php">上一页</a>
<a href="session3.php">下一页</a>
session3.php
Code
<?php
session_start();
$svar = $_SESSION['sess_var'];
if (!isset($svar)) {
echo 'var not set'.'<br />';
}
else {
echo $svar;
}
?>
<a href="session2.php">上一页</a>
posted @
2008-07-29 00:44
东捣CY
阅读(
254)
评论()
编辑
收藏
举报