Jump to content

[SOLVED] Why does this code give "header already sent" error??


JJohnsenDK

Recommended Posts

Hey

 

Here is the code

 

<?php
include('mysql_connect.php');
$query = mysql_query("SELECT counter FROM `counter` WHERE `counterId` = '1' LIMIT 1");
$sitewide=mysql_fetch_array($query);
if(!isset($_COOKIE[counter])){
	$sitewide['counter']++;
	mysql_query("UPDATE `counter` SET `counter` = '$sitewide[counter]' WHERE `counterId` = '1' LIMIT 1");
	setcookie('counter', 'snuffalufagus', 2+time()); 
}
?>

 

it starts at line 1 and ends at line 10 in a script.

 

It comes up with this error:

Warning: Cannot modify header information - headers already sent by (output started at C:\Programmer\xampp\xampp\htdocs\katrinelund\mysql_connect.php:15) in C:\Programmer\xampp\xampp\htdocs\katrinelund\index.php on line 8

 

I tried leaving out the tabs spaces, but that didnt help.

 

Any help is would be nice :)

Thanks guys that worked :D

 

Can you also tell me how the setcookie() function works?

 

I making a counter, as you properly can see and i want it to kill the cookie after 10 mins, so the homepage gets a new hit from the user after 10 min.

 

How do i do that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.