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.
<?php
isset($_SESSION[“VariableName”]) //If this return false, that mean this session is null
?>

<?php
if(isset($_SESSION[“VariableName”])){
echo “Session value:” . $_SESSION[“VariableName”];
$_SESSION[“VariableName”] = “Assigned”;
}else{
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:
session_start();

Hope you find this useful!

Leave a Reply