note 106773 deleted from function.session-status by tularis
| From: | tularis@php.net | Date: | Mon, 05 Dec 2011 21:27:46 +0000 |
| Subject: | note 106773 deleted from function.session-status by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184920@lists.php.net to get a copy of this message | ||
Note Submitter: php dot net at kenman dot net
Reason: useless
----
This is to provide for a sane way of handling the starting of a session without triggering the
E_NOTICE complaining about a session having already been started ("Notice: A session had
already been started - ignoring session_start()").
Consider:
<?php
// 1000's of lines of code, which may/may not have started a session
session_start();
?>
*If* you've already started a session, then you'll get the infamous E_NOTICE. However, you
can't really be sure that a session hasn't already been started before attempting to start
one.
Thus, the answer is:
<?php
// 1000's of lines of code, which may/may not have started a session
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
?>
See bug report @ https://bugs.php.net/bug.php?id=52982 for more
info.