Jump to content

Header Already Sent?


phpSensei

Recommended Posts

 <?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']."&notice=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']."&notice=100'>");
  
  }
    if(ucfirst($_POST['message'])=="Message"){
  
   die("Refreshing...<META HTTP-EQUIV='refresh' content='0;URL=http://localhost/forum_software/?page=newtopic&forum=".$_GET['forum']."&notice=100'>");
  
  }
  elseif(strlen($_POST['message']) > 20000){
  
     die("Refreshing...<META HTTP-EQUIV='refresh' content='0;URL=http://localhost/forum_software/?page=newtopic&forum=".$_GET['forum']."&notice=200'>");
  
  }
    elseif(strlen($_POST['title']) > 35){
  
     die("Refreshing...<META HTTP-EQUIV='refresh' content='0;URL=http://localhost/forum_software/?page=newtopic&forum=".$_GET['forum']."&notice=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']."&notice=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?

Link to comment
https://forums.phpfreaks.com/topic/66548-header-already-sent/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/66548-header-already-sent/#findComment-333314
Share on other sites

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.