Page 1 of 1

"Notice: Undefined index"

Posted: Mon Apr 12, 2004 11:47 am
by kettle_drum
Just wondering how i can get rid of this error - "Notice: Undefined index: user" when i use the following code:

Code: Select all

$this->username = strtolower(IO::xss_check($_COOKIE['user']));
user is a variable in my cookie and xss_check is a method to check for xss in the IO class. Whatever i try i just cant seem to remove the Notice message - and i dont really want to just hide the error messages.

Thanks.

Posted: Mon Apr 12, 2004 12:25 pm
by TheBentinel.com
Don't you get this message when "user" isn't a valid index into the $_COOKIE array?

Trying echo'ing $_COOKIE['user'] and see if that error's by itself and if it contains what you're expecting.

Posted: Mon Apr 12, 2004 3:30 pm
by McGruff
Check if the array element is set first:

Code: Select all

<?php
if(isset($_COOKIE['user']))
{
    // do something

} else {

    // do something else
}
?>