Jump to content

Recommended Posts

hi, I have recently been trying to debug a script and it has come up with a number of error messages, the most important (which I think is the culprit) is

 

Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/web2/discussion.php:7) in /Applications/MAMP/htdocs/web2/discussion.php on line 14

 

heres the part of the script that the error is in:

 

<?php
require("config.php");
session_start();
if($_POST['submit'])
{
	$number_of_letters = strcspn($_POST['body'], "");
	$author_letters = strcspn($_POST['author'], "");
	if($number_of_letters == 0)
	{
		header("Location: ".$config_basedir."/discussion.php?id=".$_GET['id']."&error=1");
	}
	else if($author_letters == 0)
	{
		header("Location: ".$config_basedir."/discussion.php?id=".$_GET['id']."&error=2");
	}
	else
	{
		$submit_sql = "INSERT INTO posts(topic_id, author, body, dateposted) VALUES(".$_GET['id'].", '".$_SESSION['USERNAME']."', '".$_POST['body']."', NOW());";
		mysql_query($submit_sql) or die(mysql_error());
		header("Location: ".$config_basedir."/discussion.php?id=".$_GET['id']);
	}
}

 

I've been puzzled as to what's wrong with the code. Any help would be greatly appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/129509-cannot-modify-header-information/
Share on other sites

ob_start() may work but it's more of a bandaid than a fix and used for that is not really good coding practice.  Make sure there is no output before your session_start() not even lines or whitespace.  Check your config.php as well.  Check the top and bottom of config.php since it's being required the ending whitespace/lines would be thrown in before your session_start().

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.