Gruzin Posted February 9, 2007 Share Posted February 9, 2007 Hi guys, I know it sounds dumb, but I can not get rid of this damn header error: <?php require ('config.php'); if(!isset($_COOKIE['user'])){ $user = $_SERVER['REMOTE_ADDR']; $date = date('m-Y'); $sql = mysql_query("INSERT INTO `aid_counter` (`user`, `date`, `id`) VALUES ('$user', '$date', NULL);"); setcookie("user",$user,time()+2678400); // 1 month } ?> This is a simple counter script wich I want to include somewhere , but I recieve the following error: Warning: Cannot modify header information - headers already sent by (output started at /www/cida.ge/doc/index.php:42) in /www/cida.ge/doc/admin/counter.php on line 9 Thanks for any help, george Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 9, 2007 Share Posted February 9, 2007 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment Share on other sites More sharing options...
Orio Posted February 9, 2007 Share Posted February 9, 2007 1) Make sure you don't have any output in config.php. 2) Make sure you don't have any line-breaks / spaces before the opening "<?php" in this script or in config.php. Also make sure you don't have any line-breaks / spaces after the closing "?>" in config.php Orio. Quote Link to comment Share on other sites More sharing options...
Gruzin Posted February 9, 2007 Author Share Posted February 9, 2007 Thanks Orio, here is my config.php: <?php // database connection $con = mysql_connect("localhost","XXX","XXX"); if(!$con){ die('Error:'.mysql_error()); } $db = mysql_select_db("cida_ge",$con); if(!$db){ die('Could not select database:'.mysql_error()); } $u = "http://www.cida.ge"; // edit your domain here, without backslash ?> Quote Link to comment Share on other sites More sharing options...
Orio Posted February 9, 2007 Share Posted February 9, 2007 Did you read number 2 in my post? Check! Orio. Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 9, 2007 Share Posted February 9, 2007 me and u both have same error.. and when i comment out the setcookie.. the error goes away but WTF?? no setcookie means no clientside saving really angers me off.. I yet to have solve this problem and the thing is my script worked before I have no idea what i did to it. Quote Link to comment Share on other sites More sharing options...
Gruzin Posted February 9, 2007 Author Share Posted February 9, 2007 Did you read number 2 in my post? Check! Orio. Yes, and I removed comments, but still without any luck... Thanks, George Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 headers already sent by (output started at /www/cida.ge/doc/index.php:42 What is line 42? Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 9, 2007 Share Posted February 9, 2007 FUCK I solved it U just gotta remove the linebreak spaces whatever after the ?> in ALLL INCLUDES and REQUIRES Quote Link to comment Share on other sites More sharing options...
camdagr81 Posted February 9, 2007 Share Posted February 9, 2007 you may want to buffer the output. You can do this by adding: <?php ob_start(); As your first line of code. Quote Link to comment Share on other sites More sharing options...
Gruzin Posted February 9, 2007 Author Share Posted February 9, 2007 headers already sent by (output started at /www/cida.ge/doc/index.php:42 What is line 42? <link href="css/style.css" rel="stylesheet" type="text/css"> line 42 is not php... remove the linebreak spaces whatever after the ?> in ALLL INCLUDES and REQUIRES What do u mean by that? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 So you're trying to set headers after you've output text to the browser. You have to do your setcookie BEFORE printing that HTML. Quote Link to comment Share on other sites More sharing options...
Gruzin Posted February 9, 2007 Author Share Posted February 9, 2007 OK, I've done it! Thank you very much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.