I have a third party script and was wondering how I can check with PHP
if session_start()
has been declared before doing something?
something like if(isset($_session_start())) { //do something }
It must be on every page you intend to use. The variables contained in the session—such as username and favorite color—are set with $_SESSION, a global variable. In this example, the session_start function is positioned after a non-printing comment but before any HTML.
You can check whether a variable has been set in a user's session using the function isset(), as you would a normal variable. Because the $_SESSION superglobal is only initialised once session_start() has been called, you need to call session_start() before using isset() on a session variable.
<? php if(! isset($_SESSION)) { session_start(); } ?>
session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie. When session_start() is called or when a session auto starts, PHP will call the open and read session save handlers.
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.
As in PHP >= 5.4.0, you have function session_status() that tell you if it have been initialize or not or if it's disabled.
For example you can do:
if (session_status() == PHP_SESSION_NONE) { session_start(); }
You can read more about it in http://www.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