BradD Posted June 30, 2010 Share Posted June 30, 2010 Imagine my surprise when google, yahoo, ask... have no documents with this message about header. Warning: Cannot modify header information - headers already sent by (output started at /home/database/public_html/db_insert.php:2) That's gunna make it hard to figure out, :wtf: Can anyone direct me to some info that will help me work out why I'm getting this Warning? Quote Link to comment https://forums.phpfreaks.com/topic/206275-about-header/ Share on other sites More sharing options...
magnetica Posted June 30, 2010 Share Posted June 30, 2010 Hi Gonna probably need code to go with but more than likely if your using sessions then there is either whitespace or other code before the session_start() function Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/206275-about-header/#findComment-1079123 Share on other sites More sharing options...
BradD Posted June 30, 2010 Author Share Posted June 30, 2010 Hi Gonna probably need code to go with but more than likely if your using sessions then there is either whitespace or other code before the session_start() function Hope this helps Heres the code magnetica <?php require_once('connectDB.php'); $password = md5($_POST['password']); // hash the password before the array_map() array_map('mysql_real_escape_string', $_POST); // Since only one element won't need to be sanitized, run the entire $_POST array through mysql_real_escape_string. $conf_code = md5(uniqid(rand(), true)); // generates confirmation code to use wth the confirmation email that gets sent // $query = "INSERT INTO `members` ( `firstname`, `lastname`, `username`, `password`, `accounttype`, `country`, `state`, `city`, `phone`, `mobile`, `business`, `email`, `website`, `signupdate`, `emailactivated`, `confirmed` ) VALUES ( '" . $_POST['firstname'] . "', '" . $_POST['lastname'] . "', '" . $_POST['username'] . "', '" . $password . "', '" . $_POST['accounttype'] . "', '" . $_POST['country'] . "', '" . $_POST['state'] . "', '" . $_POST['city'] . "', '" . $_POST['phone'] . "', '" . $_POST['mobile'] . "', '" . $_POST['business'] . "', '" . $_POST['email'] . "', '" . $_POST['website'] . "', now(), '" . $conf_code . "', 0 )"; mysql_query($query) or die("There has been a system problem. Failed to add record to database."); if( mysql_affected_rows() == 1 ) { $id = mysql_insert_id(); $new_record = "SELECT `firstname`, `username`, `email`, `emailactivated` FROM `members` WHERE `id` = $id"; $result = mysql_query($new_record); $array = mysql_fetch_assoc($result); $email = $array['email']; $subject = "Your confirmation code from the website"; $message = "Dear " . $array['firstname'] . ",\r\n"; $message .= "Thank you for registering at my website. To confirm your registration, please visit the link provided and enter the following confirmation code,\r\n"; $message .= $array['emailactivated']; $from = "From: [email protected]\n"; if( mail($email, $subject, $message, $from) ) { header( 'Location: success.php' ); // redirects to a "landing page" if mail was sent successfully. exit; // stops further script execution after redirect. } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/206275-about-header/#findComment-1079125 Share on other sites More sharing options...
jd307 Posted June 30, 2010 Share Posted June 30, 2010 Make sure that you do not have anything being sent to the user before your header statement (e.g. no HTML, no echo, etc.) as all of these actions send the headers, meaning you cannot modify them with a header statement afterwards. We will need to see some of your code to help you much further with this as there are a number of things that can cause header errors such as yours. I have just read that a blank line before the opening <?php tag can cause headers to be sent... though I have not tested this nor do I know how true that is. There is a whole load of information on the subject which might help you: [url http://lmgtfy.com/?q=Warning%3A+Cannot+modify+header+information+-+headers+already+sent+by+]Cannot modify header information[/url] ----------------------- Okay I have read through your code. The mail() function may be the culprit here as it creates headers and thus they cannot be modified after (Someone please correct me if I am wrong). In a situation like this, do you need to redirect the user? Could you not just use your 'success' page in an include, so if it is successful the include displays whatever that page shows instead of actually redirecting the user? There may be a way around it, but I am not sure how... assuming this is the reason. Quote Link to comment https://forums.phpfreaks.com/topic/206275-about-header/#findComment-1079126 Share on other sites More sharing options...
kenrbnsn Posted June 30, 2010 Share Posted June 30, 2010 The error message you posted output started at /home/database/public_html/db_insert.php:2 says that output was sent on line 2 of db_insert.php What is line two of that script. The mail() function may be the culprit here as it creates headers and thus they cannot be modified after (Someone please correct me if I am wrong). You're wrong. Those are different. Ken Quote Link to comment https://forums.phpfreaks.com/topic/206275-about-header/#findComment-1079274 Share on other sites More sharing options...
BradD Posted June 30, 2010 Author Share Posted June 30, 2010 OK this seems to fix it. At the top and bottom of the script you add <?php ob_start(); ?> <?php $your_script header ( 'Location: success.php') ?> <?php ob_flush(); ?> Output Buffer Start & Output Buffer Flush Quote Link to comment https://forums.phpfreaks.com/topic/206275-about-header/#findComment-1079401 Share on other sites More sharing options...
kenrbnsn Posted July 1, 2010 Share Posted July 1, 2010 That just masks the problem. It doesn't fix the root cause. Ken Quote Link to comment https://forums.phpfreaks.com/topic/206275-about-header/#findComment-1079455 Share on other sites More sharing options...
PFMaBiSmAd Posted July 1, 2010 Share Posted July 1, 2010 You probably deleted the two blank lines that were before the first opening <?php tag in your file. Quote Link to comment https://forums.phpfreaks.com/topic/206275-about-header/#findComment-1079464 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.