Jump to content


Photo

Multiple Cookies


  • Please log in to reply
2 replies to this topic

#1 natalieG

natalieG
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 21 July 2006 - 09:41 PM

We are trying to set multiple cookies with this script and  says on second cookie that
headers are already sent. How do we set multiple cookies in one file? It also never prints
out  the cookie values-last line.

Thanks,
Jennifer

<?php
if (setcookie("ABC", $value, time()+3600)){echo 'Cookie-abc Sent';}
else {echo 'cookie-abc not sent';}
if (setcookie("DEF", $value, time()+3600)){'cokkie-def sent';}
else {echo 'cookie-def not sent';}
$ABC=$_COOKIE['ABC'];
$DEF=$_COOKIE['DEF'];
print "$ABC<BR>$DEF";
?>

#2 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 21 July 2006 - 09:44 PM

You cannot send output to the browser if you wish to send more cookies / headers.

if (setcookie("ABC", $value, time()+3600)){echo 'Cookie-abc Sent';}

{echo 'Cookie-abc Sent';}

is what is causing the error.

Read the stickys.
http://www.phpfreaks...ic,37442.0.html
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php

#3 gluck

gluck
  • Members
  • PipPipPip
  • Advanced Member
  • 216 posts

Posted 21 July 2006 - 09:50 PM

Set all the cookies and only then send an output to the browser.
I'm back baby!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users