Forum : php cookie
Brief description  about Online courses   join in Online courses
View Noor  Mohammed 's Profile

php cookie

Hello sir,

I tired the example in the notes and getting this following errors. Can you please tell me why am getting these errors?

Notice: Undefined index: username in C:\wamp\www\php cookies\cookie1.php on line 5

Notice: Undefined index: colorchoice in C:\wamp\www\php cookies\cookie1.php on line 7

Many thanks and regards.
Asked by Noor Mohammed | Feb 9, 2011 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
It seems that you are not setting cookie for username and colorchoice and using the same in your program cookie1.php.

So firstly set the cookie with some value and time duration. After then you use that


Ex

<?php
$value = 'Noor Muhammad';

setcookie("myname", $value);
setcookie("myname", $value, time()+3600); /* expire in 1 hour */

if (isset($_COOKIE['myname'])) {
echo Welcome.$_COOKIE["myname"];
}



?>


Feb 9, 2011