I have a php file which starts a session, this is followed by some html. Later i include another file using include "some_file.php". The some_file.php has php and mysql interaction which is used to populate a table. Now i am starting a session in some_file.php as well, as i need to access the session variables. However i thought that the by using include i won't have to start a session again. But on doing this i get an error saying undefined session variable in some_file.php, and by using it, i get a notice saying
Notice: A session had already been started - ignoring session_start() in some_file.php/some_line
If you can't make sure your session is always started, you have to check if its started:
if(!isset($_SESSION)){
session_start();
}
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
http://docs.php.net/manual/en/function.session-status.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With