Blogger Information
Blog 39
fans 2
comment 2
visits 50805
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Notice: A session had already been started - ignoring session_start()
fighting的博客
Original
2402 people have browsed it

                                           Notice: A session had already been started - ignoring session_start() 

遇到这种问题也是无语,不知道为什么会出现这种错误,这句话翻译过来就是:session会话已开启,请忽略session_start();

解决方法:

1、简单粗暴的把session_start()删除或注销;(不严谨,不推荐)

2、考虑周到点,加个判断,使用isset()去判断,已开启就忽略,不执行,没有就开启,这样才比较合理;

if (!isset($_SESSION)) {

session_start();

}

3、这种错误级别应该不严重,在session_start()前加个@符号,忽略这次的错误。(不严谨,不推荐)

4、在php_ini中把session.auto_start =1改为0;

session.auto_start =1开启会话就自动完成了session_start(),所以如果代码里还是写session_start()的话就会重复;

0或1的区别在于:

(1)区别就在于在用SESSION前是否需要session_start();

(2)当session.auto_start = 1时,执行 session_start() 将产生新的 session_id

session.auto_start = 1 的优点在于,任何时候都不会因忘记执行 session_start() 或 session_start() 在程序里的位置不对,而导致错误

缺点在于,如果你使用的是第三方代码,则必须删去其中的全部 session_start() 。否则将不能得到正确的结果

总结:个人更加推荐使用第二种方法

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post