Jump to content

Recommended Posts

Hello guys,

              Iam getting the following php notice in the error_log:

PHP Notice:  Undefined index:  memberId in classErrorHandle.php on line 3

 

Here's the code snippet that causes this notice.

 

<?php

      2        session_start();

      3        $memberId = $_SESSION['memberId'];

      4

 

Any help is highly appreciated....

 

Cheers...

Pravin.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/105722-php-notice-undefined-index-error/
Share on other sites

it shouldn't give a notice is it is set, how are you setting it ?

$_SESSION['memberId'] = $memberId; //new /correct way

or

session_register($memberId); //old way

 

If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.

you can use sessions in classes, most common problem is either

session_start();

is not used before setting or getting the sesion values

OR

output is being sent before the session_start(); function and making it fail..

 

 

from my first post change

<?php
$memberId = (!empty($_SESSION['memberId']))?$_SESSION['memberId']:"";
?>

 

to

<?php
if (session_id() == "") session_start();
$memberId = $_SESSION['memberId'];
?>

 

check to see if you still get the errors

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.