Page 1 of 2

cookie problems

Posted: Sat Jul 06, 2002 5:06 pm
by cheatboy00
when i try to set 2 cookies i'm gettign this error

Warning: Cannot add header information - headers already sent by (output started at /home/dragonsb/public_html/cbaa/header.php:3) in /home/dragonsb/public_html/cbaa/l.php on line 13

Warning: Cannot add header information - headers already sent by (output started at /home/dragonsb/public_html/cbaa/header.php:3) in /home/dragonsb/public_html/cbaa/l.php on line 14

the code looks like this:

Code: Select all

setcookie ("idcbaa",$id,time()+604800,"/");
setcookie ("logcbaa",$stat,time()+604800,"/");
erg..

Posted: Sat Jul 06, 2002 5:25 pm
by Elfstone
Check out This post. Should have the answer to your question.

Posted: Sat Jul 06, 2002 5:53 pm
by cheatboy00
but i cant move teh setcookie any futher up the page of code.......

Code: Select all

$qry = mysql_query("SELECT * FROM users WHERE login = '$login' AND pass = '$password'");

if (mysql_num_rows($qry) == 1){ 

   setcookie ("idcbaa",$id,time()+604800,"/");
   setcookie ("logcbaa",$stat,time()+604800,"/");
becasue i need the $qry before that to check to see if i should set the cookies or not....

Posted: Sat Jul 06, 2002 5:55 pm
by Elfstone
The MySQL query wouldn't be the problem, is there any other code or HTML in that file?

Posted: Sat Jul 06, 2002 5:58 pm
by cheatboy00

Code: Select all

<?PHP

$dbh = mysql_connect ("localhost", "___", "___") or die ('I cannot connect to the database.');
   mysql_select_db ("dragonsb_xmb1");

$qry = mysql_query("SELECT * FROM users WHERE login = '$login' AND pass = '$password'");

if (mysql_num_rows($qry) == 1)&#123; 

   setcookie ("idcbaa",$id,time()+604800,"/");
   setcookie ("logcbaa",$stat,time()+604800,"/");

   $row = mysql_fetch_assoc($qry); 
   $stat = $row&#1111;'status'];
   $id = $row&#1111;'id'];
the code goes on after that... but could it be the fact, that i use this page as a sumbit result, i use a form to get login and pass then when you submit it code to this page

Posted: Sat Jul 06, 2002 6:02 pm
by Elfstone
Are you including a header.php file before using the setcookie function? The code you pasted in your last post should be the very first thing in the file before any other code or HTML.

Posted: Sat Jul 06, 2002 6:14 pm
by cheatboy00
well.. i have3 a head.php but this file is included in it... its for logingin

so in header i have...

Code: Select all

echo("<table border=1  bordercolor=#444444 cellpadding="0" cellspacing="0" width="150"><tr>");
	   		echo("<td bgcolor="#444444" width="150" align="center">");
		   		echo("<font class="heading">Control Panel</font>");
			   echo("</td></tr>");
   			echo("<tr><td>");

         if (!$page OR $page != 'login')&#123;
            include ("log.php");
         &#125;

         else if ($page == 'login')&#123;
            include ("l.php");         

            if ($page == 'login' && $ucp == 'user' OR isset ($logcbaa) == 'user')&#123;
               include ("ucp.php");
            &#125;  

            if ($page == 'login' && $ucp == 'staffer')&#123;
               include ("scp.php");
            &#125;  

            if ($page == 'login' && $ucp == 'admin1')&#123;
               include ("acp.php");
            &#125;
         &#125;
theres the part where l.php (is thefile with the cookies).. theres more html etc.. above the code i just have more html etc.....

Posted: Sat Jul 06, 2002 6:55 pm
by Elfstone
There is your problem, you sent HTML before setting the cookie, you can't do that. You need to set a cookie before ANY HTML tags have been sent, and before PHP has done anything to the page itself(echo'ing text to it, etc).

Posted: Sat Jul 06, 2002 7:14 pm
by cheatboy00
could it be possible at the top if the header.php to put somethign like this

Code: Select all

if ($check == 'y')&#123;
setcookie ......
&#125;
will that work, if i put that right at the top of the header.php page

Yeah

Posted: Sat Jul 06, 2002 10:05 pm
by icesolid
That code above is wrong. Try this.

Code: Select all

<?php
if($check == "y") &#123;
setcookie ...... 
&#125;
?>

Posted: Sun Jul 07, 2002 12:05 am
by hob_goblin
im pretty sure that it doesn't matter

Posted: Sun Jul 07, 2002 12:44 am
by cheatboy00
erg..... this is giving me a headace

Posted: Sun Jul 07, 2002 12:45 am
by cheatboy00
oh... i got an idea can you add another page onto a form.... like the action would be one thing... there would be a hidden or somethign..... well just an idea

Re: Yeah

Posted: Sun Jul 07, 2002 4:04 am
by twigletmac
icesolid wrote:That code above is wrong. Try this.

Code: Select all

<?php
if($check == "y") &#123;
setcookie ...... 
&#125;
?>
Just FYI -

Code: Select all

if ($check == 'y') &#123;
is the same thing as

Code: Select all

if ($check == "y") &#123;
Mac

Posted: Sun Jul 07, 2002 11:04 am
by LenHewitt
Cheatboy,

If you include the line:

Code: Select all

ob_start("ob_gzhandler");
after your <?php tag, it will turn on output buffering for the page and may well solve your problem