Forum Moderators: coopster

Message Too Old, No Replies

Error - Undefined index: Cookies

Error on reading value from cookies

         

kenchix1

4:52 am on Jun 7, 2005 (gmt 0)

10+ Year Member



How do I trap this error "Undefined index" when reading cookies? when I'm logged in, there is no problem, but if did not login, then this error appears. this lines is where the error occur.

$_COOKIE['sID']

please help.

thanks.

JamShady

5:07 am on Jun 7, 2005 (gmt 0)

10+ Year Member



Use isset() to make sure the variable exists before trying to access it

kenchix1

10:55 am on Jun 7, 2005 (gmt 0)

10+ Year Member



Thanks!

this is what I did on the first page:

if (!isset($_COOKIE['sID'])) {
echo "<a href='/login.php'>Login</a>&nbsp<a href ='/register.php'>Register</a>";
}

but the "Login and Register" words keeps on displaying even if I login.

dreamcatcher

3:01 pm on Jun 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code is saying 'if the cookie isn`t set, display the link'. Soo...I`m guessing...the cookie isn`t set. ;)

kenchix1

3:56 am on Jun 8, 2005 (gmt 0)

10+ Year Member



but I already login and the page say "You are logged in as [username]" but the Login and Register are still on display. :(

JamShady

8:30 am on Jun 8, 2005 (gmt 0)

10+ Year Member



There's a flaw in your logic somewhere, those two outputs should be visible at the same time logically