-3

I have been given a car registry site that was originally built using frames. I'm integrating the registry into my own site which does not use frames. I didn't code the member registration system and since pulling apart the pages that were in frames, I'm getting the following error on my site when trying to log into the registry:

 Warning: Cannot modify header information - headers already sent by 
(output started at /home/public_html/specs/registry/memberlogin.php:22) 
in /home/public_html/specs/registry/memberlogin.php on line 83

Can anyone explain what could be causing this error?

memberlogin.php:

<?
/* Check User Script */
session_start();
?>
<html>
<head><body>bunch of html code
<?
$email = $_POST['email'];
$password = $_POST['password'];

if((!$email) || (!$password)){
    echo "<p style=\"color: #FF0000; font-weight: bold; text-align: center;\">Please     enter ALL login information!</div><br />";
    include 'welcome.php';
    exit();
}

$password = md5($password);

include'dbconnect.php';
$sql = mysql_query("SELECT * FROM car_data WHERE email='$email' AND password='$password'");
$login_check = mysql_num_rows($sql);

if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
    $$key = stripslashes( $val );
}
    // Register some session variables!
    session_register('l81email');
    $_SESSION['l81email'] = $email;
    header("Location: editprofile.php");  <----- ##### THIS IS LINE 83 #####
}
} else {
include 'loginerror.php';
}
?>
</body></html>

editprofile.php:

(This script allows registered members to update their personal and car information. When the data is posted, it is sent to updateprofile.php to update the database, then this script is recalled.)

<?
//check for login
session_start();
if ( empty($l81email) ) {
echo "<center>You MUST <a href=\"welcome.php\">login</a> to proceed!</center>"; }
else {

//user is logged in
include'dbconnect.php';
$query="SELECT * FROM car_data WHERE email='$l81email'";
$result=mysql_query($query);
$rowresult = mysql_fetch_assoc($result);

mysql_close();
include 'rpodecoder.php';

?>
<-- ##### bunch of html code here.... ##### -->
<? } // end of login ELSE
?>
Gowri
  • 1,832
  • 3
  • 29
  • 53
Rob
  • 33
  • 3
  • 8
  • I saw that thread. I've checked for white space before and after and ?> and found none. – Rob Feb 05 '14 at 04:20
  • I also tried: simply write at the top of the page-- ob_start(); it will work -- and that didn't work either. – Rob Feb 05 '14 at 04:21
  • 1
    What do you think this ` bunch of html code` is right on top of your script – if _not_ output? The error message even tells you _explicitly_ where the output was started (although that doesn’t match with the code you posted here) – so this error is not really hard to find, if only one reads the error message carefully (which presumably you didn’t). – CBroe Feb 05 '14 at 04:34
  • You don't have a `Line 83` @Rob `in /home/public_html/specs/registry/memberlogin.php on line 83` so what is it and what are you leaving out? And line 22 doesn't make any sense. – Funk Forty Niner Feb 05 '14 at 04:48
  • Fred, you are correct. I posted the following response below the first reply: There is a file being included further up the top. After investigating further, that is the line 22 that the error message is referring to. So now my question is, what is the proper way to integrate html code, such as your site header and footer around the PHP code? I'm a novice when it comes to PHP and I'm trying to learn all I can. – Rob Feb 05 '14 at 04:50

1 Answers1

0

Easy Peasy!

The header() function can only be called before any information is sent to the browser. That means no html, and no text, no information at all sent to the client including bytes, spaces, lines, even cookies. You have html tags in the first code sample and echos before the header() function.

Hurricane Development
  • 2,449
  • 1
  • 19
  • 40
  • You're missing quite a lot of other potential causes. – Funk Forty Niner Feb 05 '14 at 04:32
  • In this situation? Not really that I can see. The php script is sending HTML, HEAD, and BODY tags as well as an echo before the header() – Hurricane Development Feb 05 '14 at 04:34
  • Could even be a cookie, a space, a tab, a byte order mark, etc. an include. – Funk Forty Niner Feb 05 '14 at 04:37
  • Sure this is true, will edit the post accordingly but those things do not pertain to this specific issue. – Hurricane Development Feb 05 '14 at 04:39
  • We can't know this for sure. I've seen cases exactly like that before, where it was a byte order mark that was at fault. This type of question has been asked too many times and the solution is never the same. – Funk Forty Niner Feb 05 '14 at 04:40
  • Guess its always possible – Hurricane Development Feb 05 '14 at 04:40
  • And many a time, OP's never mention the fact that they're including a file above that, or there's a seperate cookie file etc. Other times, leaving the closing PHP tag out `?>` also solves certain problems. So again, the circumstances differ from case to case. The only way to get to the bottom of "this" particular case, would be to test it with the OP's posted code. I say this from experience and I'm still learning ;) I won't go and test this one, takes too much time and may even open up a "Can of Worms". – Funk Forty Niner Feb 05 '14 at 04:43
  • Look at the OP's error message very carefully. Something doesn't "ADD" up. So this tells me, there's something that the OP isn't telling us. Line 22, line 83? There isn't 83 lines, and line 22 doesn't make sense. (memberlogin.php:22) < that means line 22 btw. – Funk Forty Niner Feb 05 '14 at 04:46
  • There is a file being included further up the top. After investigating further, that is the line 22 that the error message is referring to. So now my question is, what is the proper way to integrate html code, such as your site header and footer around the PHP code? I'm a novice when it comes to PHP and I'm trying to learn all I can. – Rob Feb 05 '14 at 04:48
  • You can try a quick patch and add `ob_start();` above `session_start();` but I won't guarantee it, since I don't know what your included file is. @Rob Take it up with LagMaster. I'm done here. Good luck. – Funk Forty Niner Feb 05 '14 at 04:51