PHP sessions that have already been started

In my PHP code, if a session has already started, and I try to start a new one, I get the following Notice:

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

How can I avoid this?

Try

<?php
    if(!isset($_SESSION)) 
    { 
        session_start(); 
    } 
?>

Notice: A session had already been started – ignoring session_start() in .. on line ..

之所以出现这种情况是页面中多次使用了 session_start()函数

有以下两种解决办法:

1) in php.ini file set session.autostart to 0 配置php.ini 设置session.autostart =0

session.auto_start = 0

2) In your code use this line 在出现错误的页面中编辑你的代码如下:

if (!session_id()) session_start();

instead of

session_start();

 
posted @ 2017-10-19 22:10  loanhicks  阅读(139)  评论(0编辑  收藏  举报