hello123456789 Posted October 22, 2008 Share Posted October 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/129509-cannot-modify-header-information/ Share on other sites More sharing options...
aniesh82 Posted October 22, 2008 Share Posted October 22, 2008 Hi Try to add a php function 'ob_start()' at the top of your page like <?php ob_start(); require("config.php"); // add other code here.... ?> Thank You, An. Joseph Quote Link to comment https://forums.phpfreaks.com/topic/129509-cannot-modify-header-information/#findComment-671453 Share on other sites More sharing options...
.josh Posted October 22, 2008 Share Posted October 22, 2008 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(). Quote Link to comment https://forums.phpfreaks.com/topic/129509-cannot-modify-header-information/#findComment-671479 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.