By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

COOKIE results in 'undefined index'

Markus
Expert 5K+
P: 6,050
In the process of making a user registration page, and if a username and or email address is already in use i set a cookie then use header( ... to redirect the user back to the page with the form.
On the page with the form, i check to see if there is reason to echo the error (if isset $_GET['i']; .. )
And then echo the cookie out.
Hooooowever, it seems the cookie isn't being recognised or i'm just silly silly silly!
[php]
// setting the cookie
setcookie('Signup_Error', "Both username and email address have been taken! Please try again", time() + 3600);
header("Location: http://localhost/blog.mahcuz.com/?i");
[/php]

[php]
// retrieving the cookie
<?php
if(isset($_GET['i']))
{
$_error = $_COOKIE['Signup_Error'];
?>
<div id="error_signup">
<?php
echo $_error;
?>
</div>
<?php
}
?>
[/php]
All this does is throw an error: undefined index: Signup_Error

If i am to cancel the header redirect and just echo the cookie out as soon as it is set, it works fine
[php]
// setting the cookie
setcookie('Signup_Error', "Both username and email address have been taken! Please try again", time() + 3600);
echo $_COOKIE['Signup_Error'];
// header("Location: http://localhost/blog.mahcuz.com/?i");
[/php]

Living up to my name.. markusn00b
;)
Feb 16 '08 #1
Share this Question
Share on Google+
1 Reply


harshmaul
Expert 100+
P: 490
Hi,
I can't reacreate the exception your getting!
You could stick the $_COOKIE refernce in a if(IsSet()) thingy....

Expand|Select|Wrap|Line Numbers
  1. if(IsSet($_COOKIE['error_list'])) {
  2. echo $_COOKIE['error_list'];
  3. }
Or whatever.
Feb 17 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.