hello to every one, I am trying to set a cookie with php because I dont know and dont understand how can I set a cookie with laravel 4 but now I am getting this error;
Undefined index: guest
and here is my php codes
<?php
if (isset($_COOKIE['guest'])) {
$guest_username = 'misafir'.$_COOKIE['guest'];
} else {
$a = rand();
setcookie('guest', $a, time()+3600, '/');
$guest_username = 'misafir'.$_COOKIE['guest'];
}
?>
Why am I getting this error or could u help me set a cookie like this? thank you.
$guest_username = 'misafir'.$_COOKIE['guest'];
On that line you probably have the error. The $_COOKIE won't be set until the next browser load. So you'd want to change that line to:
$guest_username = 'misafir'.$a;
stickman373 said:
$guest_username = 'misafir'.$_COOKIE['guest'];
On that line you probably have the error. The $_COOKIE won't be set until the next browser load. So you'd want to change that line to:
$guest_username = 'misafir'.$a;
man you saved my life! :) thank you so much.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community