I have a third party script and was wondering how I can check with PHP
if session_start()
has been declared before doing something?
if(defined('SID'))
// do
If session already started, Error: "Fatal error: Can't use function return value in write context"
Try this:
$session = session_id();
if(empty($session)){
session_start();
}
if(!isset($_SESSION)) {
session_start();
}
The check will allow you to keep your current session active even if it's a loop back submission application where you plan to reuse the form if data is typed incorrectly or have additional checks and balances within your program before proceeding to the next program.
for php >= 5.4.0
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
for php < 5.4.0
if(session_id() == '') {
session_start();
}