免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 10642 | 回复: 51
打印 上一主题 下一主题

[注销session]session_unregister和session_destroy把我弄糊涂了 [复制链接]

论坛徽章:
2
丑牛
日期:2013-09-29 09:47:222015七夕节徽章
日期:2015-08-21 11:06:17
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-06-02 09:15 |只看该作者 |倒序浏览
<?php
session_start();
if($_POST['destroy']=="Destroy Session"){
        session_unregister("destroy");
        session_destroy();
        session_unregister("name");
} else {
        if(!session_is_registered(name)) {
                session_register("name");
                $_SESSION['name'] = "Spike";
                }
}
?>
<p>SESSID: <? $id = session_id();echo $id;?>
<p>Name: <?=$_SESSION['name']?>
<form action=session2.php method=post>
<input type="submit" name="reload" value="Reload Session"><br>
<input type="submit" name="destroy" value="Destroy Session">
</form>

为什么我点击一次Destroy Session的时候,name还显示,只是不显示Id了,只有点第二次name才不显示?
session_unregister("name");不是已经把name变量给删除了吗?怎么还能打印出$_SESSION['name']?


被领导逼着学php了,没什么基础,请各位帮忙,多谢!

论坛徽章:
0
2 [报告]
发表于 2006-06-02 09:22 |只看该作者
被领导逼着学PHP?

那你就别学~

论坛徽章:
0
3 [报告]
发表于 2006-06-02 09:26 |只看该作者
如果你用PHP5,肯定不用session_unregister了
直接session_destroy();
就将$_SESSION里值全部清空了~

论坛徽章:
2
丑牛
日期:2013-09-29 09:47:222015七夕节徽章
日期:2015-08-21 11:06:17
4 [报告]
发表于 2006-06-02 09:29 |只看该作者
我用的php4

论坛徽章:
2
丑牛
日期:2013-09-29 09:47:222015七夕节徽章
日期:2015-08-21 11:06:17
5 [报告]
发表于 2006-06-02 09:30 |只看该作者
session_unregister("destroy");
        session_destroy();
        session_unregister("name");
php4里面的session_destroy();不能把所有的session变量删除吗?

论坛徽章:
0
6 [报告]
发表于 2006-06-02 09:34 |只看该作者
我一碰PHP,就是5,可能是有差异~

你以前在哪个版混~?

发贴1万3,精华39, PFPF~

论坛徽章:
0
7 [报告]
发表于 2006-06-02 09:35 |只看该作者
查看了一下,

原来你以前整BSD,搞系统维护/?

呵呵~

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
8 [报告]
发表于 2006-06-02 09:36 |只看该作者

论坛徽章:
2
丑牛
日期:2013-09-29 09:47:222015七夕节徽章
日期:2015-08-21 11:06:17
9 [报告]
发表于 2006-06-02 09:50 |只看该作者
http://www.phpx.com/man/php4gb/group.php-54.php
我看的这个手册,怎么根本就没有session_unset();
到底session有几个函数可用?糊涂了

论坛徽章:
0
10 [报告]
发表于 2006-06-02 09:53 |只看该作者
原帖由 剑心通明 于 2006-6-2 09:50 发表
http://www.phpx.com/man/php4gb/group.php-54.php
我看的这个手册,怎么根本就没有session_unset();
到底session有几个函数可用?糊涂了


不会吧~
session_destroy
(PHP 4, PHP 5)

session_destroy -- Destroys all data registered to a session
Description
bool session_destroy ( void )


session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie.

In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.

如果成功则返回 TRUE,失败则返回 FALSE。

例子 1. Destroying a session with $_SESSION

<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
    setcookie(session_name(), '', time()-42000, '/');
}

// Finally, destroy the session.
session_destroy();
?>  



注: Only use session_unset() for older deprecated code that does not use $_SESSION.




session_unset
(PHP 4, PHP 5)

session_unset --  Free all session variables
Description
void session_unset ( void )


The session_unset() function frees all session variables currently registered.

注: If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use unset() to unregister a session variable, i.e. unset ($_SESSION['varname']);.



session_unregister
(PHP 4, PHP 5)

session_unregister --  Unregister a global variable from the current session
Description
bool session_unregister ( string name )


session_unregister() unregisters the global variable named name from the current session.

This function returns TRUE when the variable is successfully unregistered from the session.

注: If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use unset() to unregister a session variable. Do not unset() $_SESSION itself as this will disable the special function of the $_SESSION superglobal.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP