PHP session中的问题

来源:互联网 发布:中南大学软件学院 编辑:程序博客网 时间:2024/05/16 11:42

在使用session的时候,遇到了类似:

代码:

<?phpsession_start();session_register("username");$_SESSION["username"] = "and00y";?>

1、Warning: session_start(): Cannot send session cache limiter - headers already sent ....
2、Fatal error: Call to undefined function session_register() in ...


解决方法:

1.1、如果使用基于cookie的session(cookie-based sessions),那么在使用Session_start()之前浏览器不能有任何输出,否则会出现"Cannot send session cache limiter – headers already sent"错误,所以首先要确保Session_start()在开始输出之前执行,一般直接放到php文件的最上方. 摘自:http://www.noonenet.cn/newshtml/newsinfor/php-sessionstart-error.html

1.2、也可以在session_start()前加“@”省去警告。

2、在5.4之后,session不需要用register注册了,直接使用$_SESSION["username"] = "and00y",就行。(注销这种方式的session变量时,要用unset($SESSION["username"]),注销会话的时候,都用session_unset(),注销会话不能用unset();


如要使用session,记得在页面前加session_start();


原创粉丝点击