By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,269 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,269 IT Pros & Developers. It's quick & easy.

Warning: Cannot modify header information

P: 14
Hi I get this error code when I try to run my login script.
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\Rising sun\css.php:1) in C:\Program Files\Apache Group\Apache2\htdocs\Rising sun\loginmeth.php on line 24
This is the login script stored in loginmeth.php ;
[php]<?php require_once 'config.php';?>
<?php include 'opendb.php';?>
<?php $errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {

$userId = $_POST['txtUserId'];
$password = $_POST['txtPassword'];
$_SESSION['userid'] = $userId;
// check if the user id and password combination exist in database
$sql = "SELECT *
FROM contactd
WHERE email = '$userId' AND password = PASSWORD('$password')";
//WHERE user_id = '$userId' AND user_password = PASSWORD('$password')";

$result = mysql_query($sql)
or die('Query failed. ' . mysql_error());

if (mysql_num_rows($result) == 1) {
// the user id and password match,
// set the session
$_SESSION['db_is_logged_in'] = true;

// after login we move to the main page
header('Location: cart.php');
exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}


}
?>[/php]
and all i have in the css.php is
[php] <?php ?>
<style type="text/css">
body { background-color: #000000; font-family: Arial, Helvetica, sans-serif; color: #ffffff }
a:link { color: #ffffff }
a:visited { color: #ffffff }
a:hover { color: #000080 }
a:active { color: #ff6666 }
</style>[/php]
Im guessing that the problem is in the css.php but im not sure why. I check and removed all extra white spaces at the end and beginnning of the <?php ?> tags but it hasn't cured it.

Also what does" header('Location: cart.php'); " Im guessing it sends you to the page specified after you login ?
Dec 12 '06 #1
Share this Question
Share on Google+
4 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Pity you don't show us how you include the css.php. But the problem is definitely in that file. Look at the first statement in there
Expand|Select|Wrap|Line Numbers
  1. <?php ?>
that one generates a blank char to output and ... headers sent!
You should not use css in a php file. The usual way to include css is to have a separae CSS file, without any PHP statements or <style> statements and then do a
Expand|Select|Wrap|Line Numbers
  1. <link rel="stylesheet" href="file.css" type="text/css" />
So remove the first statement in the css file.

Ronald :cool:
Dec 12 '06 #2

P: 14
My mistake! The css.php is called in all of the pages by,
[php]<?php require_once 'css.php';?>[/php]
It is under the <?php require_once 'config.php';?> on every page. Should I just use you code one the config page and then it will be called by the config page?
Dec 12 '06 #3

P: 14
Okay it moaned when I put the css script link in the config file so I have put it in all the files. The error that I had has gone away :) but has been replaced by another:(
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\Rising sun\login.php:16) in C:\Program Files\Apache Group\Apache2\htdocs\Rising sun\loginmeth.php on line 24
This is the code for the login in page;
[php]<?php require_once 'config.php';?>
<link rel="stylesheet" href="rscss.css" type="text/css" />
<html>
<body>
<br />
<br />
<br />
<br />
<br />
<table width="50%" border="1">
<tr>
<th scope="col"><h2>Log In</h2> for existing customers</th>
<th scope="col"><h2>Register</h2>if you are new to the site</th>
</tr>
<tr>
<td><?php include 'loginmeth.php';?></td>
<td><?php require_once 'regmeth.php';?></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<?php echo "Item picked = ". $_SESSION['cartadd'];?>
</body>
</html>[/php]
And this is the loginmeth page;
[php]<?php require_once 'config.php';?>
<?php include 'opendb.php';?>
<?php $errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {

$userId = $_POST['txtUserId'];
$password = $_POST['txtPassword'];
$_SESSION['userid'] = $userId;
// check if the user id and password combination exist in database
$sql = "SELECT *
FROM contactd
WHERE email = '$userId' AND password = PASSWORD('$password')";
//WHERE user_id = '$userId' AND user_password = PASSWORD('$password')";

$result = mysql_query($sql)
or die('Query failed. ' . mysql_error());

if (mysql_num_rows($result) == 1) {
// the user id and password match,
// set the session
$_SESSION['db_is_logged_in'] = true;

// after login we move to the main page
header('Location: test.php');
exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}


}
?>
<?php include 'closedb.php';?>
// html table stuff after here[/php]

I dont understand why its complaining. Also it doesnt seem to link to the specifed page.
Dec 12 '06 #4

ronverdonk
Expert 2.5K+
P: 4,258
I am sure you still have some outputting in one of your scripts, e.g. config.php or still the css file? Even a simple blank is enough to kill it. Have a look for certain,

Ronald :cool:
Dec 12 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.