JJohnsenDK Posted April 24, 2007 Share Posted April 24, 2007 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 Link to comment https://forums.phpfreaks.com/topic/48420-solved-why-does-this-code-give-header-already-sent-error/ Share on other sites More sharing options...
mmarif4u Posted April 24, 2007 Share Posted April 24, 2007 Canu show ur index.php code. OR: put this ayt very top of ur index.php page. <?php ob_start(); ?> Link to comment https://forums.phpfreaks.com/topic/48420-solved-why-does-this-code-give-header-already-sent-error/#findComment-236759 Share on other sites More sharing options...
bsprogs Posted April 24, 2007 Share Posted April 24, 2007 If I remember correctly, header information must be sent before ANY html is written to the page. Check this file: C:\Programmer\xampp\xampp\htdocs\katrinelund\mysql_connect.php and see what line 15 says. Link to comment https://forums.phpfreaks.com/topic/48420-solved-why-does-this-code-give-header-already-sent-error/#findComment-236761 Share on other sites More sharing options...
JJohnsenDK Posted April 24, 2007 Author Share Posted April 24, 2007 Thanks guys that worked 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? Link to comment https://forums.phpfreaks.com/topic/48420-solved-why-does-this-code-give-header-already-sent-error/#findComment-236763 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.