How to send cookie to the next page??

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
azhan
Forum Commoner
Posts: 68
Joined: Fri Jun 27, 2008 6:05 am

How to send cookie to the next page??

Post by azhan »

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


hey guys...i have problems with setcookie and sending it to the next page..it returns "cannot modify header, header already send in (C://....) in line... "

below are my codes....could u guys see if i did anything wrong
------------------------------------------------------------------------------------

Code: Select all

<?php
// Connects to your Database 
mysql_connect("localhost", "root", "password") or die(mysql_error()); 
mysql_select_db("hospital") or die(mysql_error()); 
 
$id = $_COOKIE['ID_my_site']; 
$take = mysql_query("SELECT name FROM patientlist WHERE id = '$id'");
while ($taking = mysql_fetch_array($take)) {
 echo "Retrieving Images From Patient Named: <fontcolor='red'>".$taking["name"]."</font><br>\n";
 print "Below are the title of the currently stored images, click on the title to view" ;
  } 
  
$id = $_COOKIE['ID_my_site']; 
$result = @mysql_query("SELECT * FROM pix WHERE pid ='$id'");
while ($list = mysql_fetch_array($result)) 
{
if (!$result) {
die( ' no data');}
else {
$value = '"'.$list['title'].'"';
setcookie("TestCookie", $value);                                                               //line21
setcookie("TestCookie", $value, time()+3600);  /* expire in 1 hour */              //line22
setcookie("TestCookie", $value, time()+3600, "/~rasmus/", ".picture.php", 1);   //line23
echo "<br><a href='picture.php'>".$list['title']."</a>"; }}
?>

and it return this
-------------------------------------------------------------------------------------
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\get2.php:9) in C:\xampp\htdocs\get2.php on line 21

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\get2.php:9) in C:\xampp\htdocs\get2.php on line 22

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\get2.php:9) in C:\xampp\htdocs\get2.php on line 23

katil
--------------------------------------------------------------------------------------
where "katil" is my $list['title'] value

my next page is picture.php....but when i click the word "katil" which wanted to go to the next page...there is no image which seems no cookie had been send from previous page.

by the way..what should i replace this "/~rasmus/", ??




thanks,
Azhan
________________________
http://www.productcoverdesign.com- "Cheapest E-Cover Design"


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: How to send cookie to the next page??

Post by jaoudestudios »

You can not resend headers once they are sent to the screen.

Basically, if you want to resend or append the headers you can not have any white space or echo's before!
Post Reply