php中session的使用

php里使用session比较简单,通过session_start();启动sesssion会话功能(也可以在php 配置文件里设置 session.auto_start =1 这样就不需要调用session_start(),直接就能使用session),且该语句在脚本中必须放在所有输出语句之前(php手册中有的If you are using cookie-based sessions, you must call session_start() before anything is outputted to the browser.)。

然后直接像使用数组一样操作$_SESSION数组即可,比如$_SESSION['something']='nothing'.即可完成设置和修改。

至于提前销毁session,使用session_unset();函数即可销毁该会话的session记录。

更详细的关于php中session机制的理解参见www.cnblogs.com/acpp/archive/2011/06/10/2077592.html

posted @ 2014-09-06 19:54  Summer_cool  阅读(916)  评论(0编辑  收藏  举报