Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Hi everyone I got some trouble with sessions that I use on my little project:

PHP Notice:  Undefined index: user_ID in ../config/sessions_class.php on line 29

(this is from the nginx error.log)

If tried setting the save path for sessions to memcache and to /var/lib/php5/sessions. Session files actually get created in the sessions directory, so the user permissions must be correct. I'm currently saving user settings to sessions such as $_SESSION['user_ID'] on index.php and then redirecting to anotherpage.php. If I try to retrieve $_SESSION['user_ID'] there I get the undefined index error. session_start gets called several times, but this shouldnt be the problem I guess.

Any suggestions where the problem might be? I can append nginx.conf or php.ini files if you wish.

EDIT: I got Suhosin PHP Hardening - any chance this might interfere with the global SESSION variables?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This is a PHP notice for your $_SESSION superglobal array (which behaves like most any other array when an index is not defined).

The notice indicates that, when $_SESSION was checked for a key named "user_ID", none was found; you'll see this notice if you have a conditional like the following:

if ( $_SESSION['user_ID'] != 0 ) {
  // ...
}

One workaround would be to use the isset() function on $_SESSION['user_ID'] instead:

if ( isset( $_SESSION['user_ID'] ) ) {
  // ...
}

You might consider revisiting your error reporting configuration if you would prefer to stop seeing notices in your logs.

share|improve this answer
    
thanks. I checked again if it was really set and it wasnt. the problem however was that the domain for the session cookie was set to another domain. setting it to the correct one allowed the sessid to get passed correctly. –  jcfrei Sep 1 '10 at 21:28
    
I'd upvote your answer if you hadn't suggested he didn't log notices. :( –  Martin Fjordvald Sep 2 '10 at 7:59
    
@Martin F - I find it disheartening that one can be down-voted for providing correct information and leaving it up to the user to determine what's best for his purposes... –  danlefree Sep 2 '10 at 15:16
    
I'm not down voting at all, your answer is correct and would certainly not deserve to be down voted. I still think you should edit out the part about not logging notices, though. –  Martin Fjordvald Sep 2 '10 at 17:11
    
I agree with Martin F. I throw exceptions for any type of PHP error on any projects that I start including E_STRICT. The best way to stop seeing errors is to never create them in the first place. –  Tres May 27 '11 at 3:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.