PHP Session Problem

When I try to use the Session variable in PHP $_Session[“VariableName”], it does not work….
The session never get registered.

How to check?
You can use the following code to see if the Session is null or not.
isset($_SESSION[“VariableName”]) //If this return false, that mean this session is null

echo “Session value:” . $_SESSION[“VariableName”];
$_SESSION[“VariableName”] = “Assigned”;
echo “Session is null”;

If the result is “Session is null“, once you refresh the page again, it should display “Session value: Assigned”.

If not, that mean the Session feature has not been turn on properly on you server.

Solution 1:
If you are allowed to modify the php.ini file, you can open up the “php.ini” file and Search for the keyword “session.auto_start
To ensure
session.auto_start= 1;
After you edited it, you can restart the web sever and try again.

Solution 2:
You can use the follow code to enable the session feature:

Hope you find this useful!

Leave a Reply