Raja Gopal Raja Gopal - 1 year ago 95
PHP Question

PHP session notice:undefined index

I am trying to pass a value using session from one page to another but it says

Notice: Undefined index: user_id in path\file.php on line 61

The file where i am creating session is as follows

// checking for session, if not then start session
if(!isset($_SESSION)) {
// assigning user_id to session var

This is the code by which, i am accessing session var:

if(!isset($_SESSION)) {
// trying to access session var (previously defined)

Where i am making mistake. Kindly guide me please

Answer Source

It should be $_SESSION not $_session.


 $user_id = $_SESSION['user_id'];

$_SESSION is a global variable and should be written in capital. When you are using the variable with small letters, in that case it doesn't get the variable because its never been defined and doesn't have the key user_id and hence you get the error. Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download