Jump to content

VERY unusual Header Error


brax23

Recommended Posts

I'm running three separate machines all set up the same (localhost).  On two of the machines my code runs fine but on the third I get "Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\mps\index.php:8) in C:\Program Files\Apache Group\Apache2\htdocs\mps\index.php on line. . ."  Can't figure this one out since all htree machines are set up identically.

 

Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/109090-very-unusual-header-error/
Share on other sites

I've copied/pasted this code onto the three machines.  2 work fine.  The only differences are the un/pw for the db's and the computer names.  All I do is change the un & pw in the code to match each machines db.  On 2 machines this works fine but he third gives me the warnings.  If I comment out the offending lines I simply get redirected to the same page (index.php) and get the ominous white space.  Can't figure why this only occurs on one of my machines.  Here's the code:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>MPS PROJECT RACKING - BY TIMETEK, INC.</title>

</head>

 

<?php

 

$mysql_hostname = "localhost";

$mysql_username = "walt";

$mysql_password = "nexus1288";

$mysql_database = "mps";

 

$mysql_connect = mysql_connect("$mysql_hostname", "$mysql_username", "$mysql_password") or die(mysql_error());

 

mysql_select_db("$mysql_database") or die(mysql_error());

 

if (isset($_COOKIE['ID_my_site']))

 

{

 

$username = $_COOKIE['ID_my_site'];

$password = $_COOKIE['Key_my_site'];

 

$check = mysql_query("SELECT * FROM mps_login WHERE username = '$username'") or die(mysql_error());

 

while($info = mysql_fetch_array($check))

 

{

 

if ($password != $info['password'])

 

{

 

}

 

else

 

{

 

header("location: http://localhost/mps/home.php");

 

}

 

}

 

}

 

if (isset($_POST['submit']))

 

{

 

if(!$_POST['username'] | !$_POST['password'])

 

{

 

die('You have failed to complete all required fields.<br /><br />Please <a href="http://localhost/mps/index.php">login</a> or <a href="http://localhost/mps/register.php">register</a>.');

 

}

 

if (!get_magic_quotes_gpc())

 

{

 

//$_POST['email'] = addslashes($_POST['email']);

 

}

 

$check = mysql_query("SELECT * FROM mps_login WHERE username = '".$_POST['username']."'") or die(mysql_error());

$check_two = mysql_num_rows($check);

 

if ($check_two == 0)

 

{

 

die('That user does not exist in our database.<br /><br />Please <a href="http://localhost/mps/index.php">login</a> or <a href="http://localhost/mps/register.php">register</a>.');

 

}

 

while($info = mysql_fetch_array( $check ))

 

{

 

$_POST['password'] = stripslashes($_POST['password']);

$info['password'] = stripslashes($info['password']);

$_POST['password'] = md5($_POST['password']);

 

if ($_POST['password'] != $info['password'])

 

{

 

die('Incorrect password.<br /><br />Please <a href="http://localhost/mps/index.php">login</a> or <a href="http://www.game-zero.org/mps/register.php">register</a>.');

 

}

 

else

 

{

 

$_POST['username'] = stripslashes($_POST['username']);

 

$hour = time() + 3600;

 

setcookie(ID_my_site, $_POST['username'], $hour);

setcookie(Key_my_site, $_POST['password'], $hour);

 

header("location: http://localhost/mps/home.php");

 

}

 

}

 

}

else

 

{

 

?>

 

<body>

 

 

<br />

<a href="http://localhost/mps/register.php">Register</a>

 

 

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">

<table class="center" border="0">

<br />

<tr><td colspan="2"><p>LOGIN:</p></td></tr>

<tr><td>Username:</td><td>

<input type="text" name="username" value="" maxlength="40">

</td></tr>

<tr><td>Password:</td><td>

<input type="password" name="password" value="" maxlength="50">

</td></tr>

<tr><td colspan="2" align="right">

<input type="submit" name="submit" value="Login">

</td></tr>

</table>

</form>

 

</body>

</html>

 

<?php

 

}

 

?>

Sorry for the protocol error.  All three php.ini files are identical since I copies and pasted the original onto the other 2 machines.  Still can't figure this one out.  The code is on a page called Index.php.  When the warning causing lines are commented out the page simply redirects itself back to itself and gives white space, but only on one machine.  Here's the offending code properly posted:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>MPS PROJECT RACKING - BY TIMETEK, INC.</title>
</head>

<?php

$mysql_hostname = "localhost";
$mysql_username = "walt";
$mysql_password = "nexus1288";
$mysql_database = "mps";

$mysql_connect = mysql_connect("$mysql_hostname", "$mysql_username", "$mysql_password") or die(mysql_error());

mysql_select_db("$mysql_database") or die(mysql_error());

if (isset($_COOKIE['ID_my_site']))

{

$username = $_COOKIE['ID_my_site'];
$password = $_COOKIE['Key_my_site'];

$check = mysql_query("SELECT * FROM mps_login WHERE username = '$username'") or die(mysql_error());

while($info = mysql_fetch_array($check))

{

if ($password != $info['password'])

{

}

else

{

header("location: http://localhost/mps/home.php");

}

}

}

if (isset($_POST['submit']))

{

if(!$_POST['username'] | !$_POST['password'])

{

die('You have failed to complete all required fields.<br /><br />Please <a href="http://localhost/mps/index.php">login</a> or <a href="http://localhost/mps/register.php">register</a>.');

}

if (!get_magic_quotes_gpc())

{

//$_POST['email'] = addslashes($_POST['email']);

}

$check = mysql_query("SELECT * FROM mps_login WHERE username = '".$_POST['username']."'") or die(mysql_error());
$check_two = mysql_num_rows($check);

if ($check_two == 0)

{

die('That user does not exist in our database.<br /><br />Please <a href="http://localhost/mps/index.php">login</a> or <a href="http://localhost/mps/register.php">register</a>.');

}

while($info = mysql_fetch_array( $check ))

{

$_POST['password'] = stripslashes($_POST['password']);
$info['password'] = stripslashes($info['password']);
$_POST['password'] = md5($_POST['password']);

if ($_POST['password'] != $info['password'])

{

die('Incorrect password.<br /><br />Please <a href="http://localhost/mps/index.php">login</a> or <a href="http://www.game-zero.org/mps/register.php">register</a>.');

}

else

{

$_POST['username'] = stripslashes($_POST['username']);

$hour = time() + 3600;

setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['password'], $hour);

header("location: http://localhost/mps/home.php");

}

}

}
else

{

?>

<body>


<br />
<a href="http://localhost/mps/register.php">Register</a>


<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table class="center" border="0">
<br />
<tr><td colspan="2"><p>LOGIN:</p></td></tr>
<tr><td>Username:</td><td>
<input type="text" name="username" value="" maxlength="40">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="password" value="" maxlength="50">
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
</td></tr>
</table>
</form>

</body>
</html>

<?php

}

?>

Just for giggles you should run phpinfo() on all three machines and see if output buffering is set the same...

 

Running php on two different windows systems once, I had a similar problem... I had copied the ini from one system to the other in the same location (windows folder) the thing was, the second server was pulling an ini that I had in the php root folder instead of the one I had copied over...

 

Just a thought.

Archived

This topic is now archived and is closed to further replies.

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