phpSensei Posted August 24, 2007 Share Posted August 24, 2007 <?php mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("forum")or die(mysql_error()); $switch=strip_tags($_GET['do']); switch($switch){ case 'newtopic': if(isset($_POST['Submit'])){ if(empty($_POST['title'])||empty($_POST['message'])){ die("Refreshing...<META HTTP-EQUIV='refresh' content='0;URL=http://localhost/forum_software/?page=newtopic&forum=".$_GET['forum']."¬ice=100'>"); } if(ucfirst($_POST['title'])=="Topic Title"){ die("Refreshing...<META HTTP-EQUIV='refresh' content='0;URL=http://localhost/forum_software/?page=newtopic&forum=".$_GET['forum']."¬ice=100'>"); } if(ucfirst($_POST['message'])=="Message"){ die("Refreshing...<META HTTP-EQUIV='refresh' content='0;URL=http://localhost/forum_software/?page=newtopic&forum=".$_GET['forum']."¬ice=100'>"); } elseif(strlen($_POST['message']) > 20000){ die("Refreshing...<META HTTP-EQUIV='refresh' content='0;URL=http://localhost/forum_software/?page=newtopic&forum=".$_GET['forum']."¬ice=200'>"); } elseif(strlen($_POST['title']) > 35){ die("Refreshing...<META HTTP-EQUIV='refresh' content='0;URL=http://localhost/forum_software/?page=newtopic&forum=".$_GET['forum']."¬ice=300'>"); } else { $title=htmlentities($_POST['title']); $message=htmlentities($_POST['message']); $title=mysql_real_escape_string($title); $message=mysql_real_escape_string($message); $id=strip_tags($_GET['forum']); $id=mysql_real_escape_string($id); $date=date('Y-m-d H:i:s'); $query=mysql_query("insert into topics (id_forum,title,message,reply_date) VALUES ('$id','$title','$message','$date')") or die (mysql_error()); $result=mysql_query("SELECT * FROM topics ORDER BY reply_date DESC LIMIT 1"); $data=mysql_fetch_assoc($result); $date2=$data['reply_date']; $update=mysql_query("update forum_title SET last_topic = '$date2' WHERE id = '$id'"); $update=mysql_query("update forum_title SET total_topic = total_topic + 1 WHERE id = '$id'"); $ip=$_SERVER['REMOTE_ADDR']; setcookie("flood",$ip,time()+30); die("Refreshing...<META HTTP-EQUIV='refresh' content='0;URL=http://localhost/forum_software/?page=newtopic&forum=".$_GET['forum']."¬ice=500'>"); } } break; } ?> I cant set a cookie because the header has already been sent? I dont get it, and the code is outside the head tags, on top of my page. Help? Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/ Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 I believe there is a sticky about this: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333298 Share on other sites More sharing options...
dbo Posted August 24, 2007 Share Posted August 24, 2007 My guess is that one of the meta refresh things is being echo'd before you attempt to set the cookie... thus headers sent. Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333299 Share on other sites More sharing options...
phpSensei Posted August 24, 2007 Author Share Posted August 24, 2007 The Script is on top of everything, meaning line 1, so the only META comes after the setcookie. Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333302 Share on other sites More sharing options...
dbo Posted August 24, 2007 Share Posted August 24, 2007 If any of your queries fail it will send headers. That may or may not be the case... I dunno. But what I do know is that computers only do what you tell them (despite what we sometimes think) somewhere there is a problem with your script.... not php lying Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333308 Share on other sites More sharing options...
phpSensei Posted August 24, 2007 Author Share Posted August 24, 2007 lol, Okay, I will take a better look at it, but keep in my mind, the data is sent to the database and no query fails at all. Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333310 Share on other sites More sharing options...
GingerRobot Posted August 24, 2007 Share Posted August 24, 2007 Unless im being completely blind, you've not included the part of the code that sets the cookie. Therefore, we can't suggest where the output is coming from. Also, the error message will tell you what line the header was already sent by. It would be useful to have that information. Help us help you. Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333314 Share on other sites More sharing options...
dbo Posted August 24, 2007 Share Posted August 24, 2007 If the script is online do you have a link I can view it at? Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333318 Share on other sites More sharing options...
phpSensei Posted August 24, 2007 Author Share Posted August 24, 2007 Its not online, but I can uploaded to my current free host... Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333320 Share on other sites More sharing options...
dbo Posted August 24, 2007 Share Posted August 24, 2007 please do so if you dont care Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333325 Share on other sites More sharing options...
phpSensei Posted August 24, 2007 Author Share Posted August 24, 2007 So sorry man, It Keeps showing up blank because the stupid host does not support php. How ridiculious.... I will try it on other servers, then update you about it. Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333336 Share on other sites More sharing options...
phpSensei Posted August 24, 2007 Author Share Posted August 24, 2007 I dont know if this link will work, but hope for the best... http://nasir.prohosts.org/test/ Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333343 Share on other sites More sharing options...
dbo Posted August 24, 2007 Share Posted August 24, 2007 It did a whole lot of nothing... no errors... no output... nothing. So that might mean it worked? Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333346 Share on other sites More sharing options...
phpSensei Posted August 24, 2007 Author Share Posted August 24, 2007 Well, It was a blank page right? I mean, It runs the script only when you post a new topic in the forum. Quote Link to comment https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333349 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.