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?
The answer is "no". You cannot start multiple sessions simultaneously. And if you do, you'll get an error like "A session had already been started". You don't need to start simultaneous sessions, so long you can create multiple keys.
Make use of isset() function to check if session variable is already set or not.
Unless you have output buffering enabled, the session_start() must come before anything other than headers are sent to the browser (as it sets a cookie in the header). It must come before you attempt to reference the $_SESSION data.
Try
<?php if(!isset($_SESSION)) { session_start(); } ?>
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