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)
Use isset() to make sure the variable exists before trying to access it
kenchix1
10:55 am on Jun 7, 2005 (gmt 0)
Thanks!
this is what I did on the first page:
if (!isset($_COOKIE['sID'])) { echo "<a href='/login.php'>Login</a> <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)
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)
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)
There's a flaw in your logic somewhere, those two outputs should be visible at the same time logically