Jump to content

Recommended Posts

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: :wtf: :wtf:

 

Can anyone direct me to some info that will help me work out why I'm getting this Warning?

Link to comment
https://forums.phpfreaks.com/topic/206275-about-header/
Share on other sites

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.
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/206275-about-header/#findComment-1079125
Share on other sites

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. 

Link to comment
https://forums.phpfreaks.com/topic/206275-about-header/#findComment-1079126
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/206275-about-header/#findComment-1079274
Share on other sites

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.