isset($_SESSION) Not Working on Remote Server

I have a login page where user enters his username ans password. If successful I redirect him to index.php where I start a session:

session_start();

from index.php he can navigate to a different page (“p1.php”) and on top of “p1.php” I have this check:

<?php
if(!isset($_SESSION)) 
{ 
    exit;
} 
?>

This works on my local server, but when I deploy this on remote server !isset($_SESSION) always returns true.

What could be happening here?

EDIT: I found on my hosting provider side a request to add this in php.ini:

session_save_path("your home directory path"/phpsessions);

And to create a phpsessions folder in my path.

I did but that didn’t help.

I tried to do this as well:

in index.php:

session_start();
if(isset($_REQUEST['lecturer_id']))
{
    echo "lecturer_id set";
    $_SESSION['lecturer_id'] = $_REQUEST['lecturer_id']; // store session data
}

and in p1.php: session_start(); if(!isset($_SESSION[‘lecturer_id’])) { exit; }

And the page always exits i.e. session variable is not defined

Answer

You’ll just need to make sure you have session_start(); at the very top of your p1.php page and any page that uses session data.

Leave a Reply

Your email address will not be published. Required fields are marked *