cookie setting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

cookie setting

Post by shiznatix »

at the top of my script i have

Code: Select all

if (isset ($_POST['remember'])){
setcookie ('name', $name, time()+60*60*24*30, '/', '', 0);
}
then at the bottom of my script i have

Code: Select all

if (isset($_COOKIE['name'])){
$message = $message.'*,*:!.-'.$_COOKIE['name'].'*,*:!.-'.$ip.'*,*:!.-'.$num;
}else{
$message = $message.'*,*:!.-NULL*,*:!.-'.$ip.'*,*:!.-'.$num;
}
but the cookie dosnt seam to get set until the script is completly finished so it takes it 2 runs for it to work. is there any way i can have the cookie set before the script reaches the end??
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

If you have read up on cookie, you would have known that the cookie you set in the first part/top of script wouldn't show up until the next response from the client where it would get set on the next response. So mind that.
Post Reply