The easy ways of using the PHP session are documented here:
The PHP session_id() function returns a value:
The return value will always be true with respect to isset(), but your release level of PHP may not allow you to test with isset() when your script tests the return value of a function.
Can you please tell us in plain language, what are you trying to achieve with this if() statement? The usual way of working with the session would just start the session at the beginning of the script and would never need to test to see if the session had been started!
If you have to write conditional code to determine whether the session is started or not, there is a design flaw in the application. “Housekeeping” things like setting the error reporting, starting the session, and connecting to the database should always be done unconditionally at the logical top of the application. Often these things are factored out of inline code into a common script that gets brought in with a require_once statement. Then the PHP scripts that build the web pages start like this:
And in session.php we have something like this:
The session.php script is also a convenient place to store your class and function definitions if you're not using an autoloader.