Forum Moderators: coopster

Message Too Old, No Replies

modify header information

         

fenomen

7:23 pm on Oct 2, 2005 (gmt 0)

10+ Year Member



i have a cookie problem.

Warning: Cannot modify header information - headers already sent by (output started at ~aaa.php:2) in ~aaa.php on line 109

Line 109: setcookie("aaa", $GLOBALS['id'], time()+86400*100);

what is wrong?

mcibor

7:45 pm on Oct 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This error means that you are sending some text before setting the cookie:

<?php
echo "a";
print("a");
setcookie("a", "a", 0);//your error!

but also

<?php
setcookie(...);//your error!

There's a white space on the beginning of the file

Cookies, headers and session_start must be set before anything is sent to the client!

Hope this helps

<?php
$a = 2 + 2 * 2;
setcookie("a", $a, 0);//works fine!

Best regards
Michal Cibor

fenomen

8:25 pm on Oct 2, 2005 (gmt 0)

10+ Year Member



but i created another .php files.


<html><head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
</head><body>

<?php
setcookie("aaa", "bbb", time()+86400*100, "/", "");
$deneme = $_COOKIE["aaa"];
echo $deneme;
?>

</body></html>

problem is same..
Warning: Cannot modify header information - headers already sent by ...

dreamcatcher

8:55 pm on Oct 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is as described my Michal, you are sending data to the browser before you call the set cookie function. Try this:


<?php
setcookie("aaa", "bbb", time()+86400*100, "/", "");
$deneme = $_COOKIE["aaa"];
?>

<html><head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
</head><body>

<?php
echo $deneme;
?>

</body></html>

dc

mcibor

9:17 pm on Oct 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dreamcatcher! This won't work!

You cannot read the Cookie just after it is set. It will work on the next reload of the site.

Otherwise it's fine. I told you not to put anything, not even white space before <?php setcookie(...);

Best regards
Michal Cibor

fenomen

9:54 pm on Oct 2, 2005 (gmt 0)

10+ Year Member



my code is :

<?
include "admin/config.php";

$Sql = @mysql_query("SELECT * FROM table WHERE number='1'");
$id = @mysql_result($Sql, 0, 'id');
$quest = @mysql_result($Sql, 0, 'quest');

$asec = @$_POST["asec"];
setcookie("aaa", $id, time()+86400*100, "/", "");
mysql_query("UPDATE table SET qqq = qqq + 1 WHERE id='$asec'");
}

$kuukie = @$_COOKIE["aaa"];
if ($kuukie==.....
....
....

?>
<html><head>....

but problem is same still...

henry0

10:42 pm on Oct 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How does that read :)


not even white space before <?php setcookie(...);

give it a try

Cheers

dreamcatcher

6:59 am on Oct 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You cannot read the Cookie just after it is set. It will work on the next reload of the site.

Sure. I was just showing that the cookie data needed to go before the HTML data.

dc

mcibor

9:46 pm on Oct 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What's in the config.php? Maybe you echo some data there?

Try this to make sure, that you don't echo anything:

<?
include "admin/config.php";

$Sql = @mysql_query("SELECT * FROM table WHERE number='1'");
$id = @mysql_result($Sql, 0, 'id');
$quest = @mysql_result($Sql, 0, 'quest');

$asec = @$_POST["asec"];
die("Only this should show. Nothing else!");
setcookie("aaa", $id, time()+86400*100, "/", "");

If only the text "Only this should show. Nothing else!" shows, then the problem lies somewhere else. If there's abything in there, it shouldn't be there!
See the source code to see the details!
Michal Cibor

fenomen

10:13 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



text is shown.
i sent all of code, i hope, you find that problem.


$host = 'aaa';
$user = 'aaa';
$pass = 'aaa';
$dbname = 'aaa';
$mysql = mysql_connect($host,$user,$pass);
$db = mysql_select_db($dbname,$mysql);

$Sqlm =@mysql_query("SELECT * FROM table WHERE number='1'");
$id = @mysql_result($Sqlm, 0, 'id');
$Soru = @mysql_result($Sqlm, 0, 'Soru');

// Eğer oy gönderildiyse hit arttiriyoruz
$asec = @$_POST["asec"];
if (@$_GET["h"]=="s" && $asec<>"") {
setcookie("Cook", $id, time()+86400*100, "/", "");
mysql_query("UPDATE tablo SET qqq = qqq + 1 WHERE id='$asec'");
}