473,395 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Warning: Cannot modify header information

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
4 2045
ronverdonk
4,258 Expert 4TB
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
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
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
4,258 Expert 4TB
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

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

Similar topics

1
by: None | last post by:
Hello, I am a total newbie to PHP and programming in general. I am playing around with a PHP / MySQL shopping cart script which I found at...
3
by: Greg Scharlemann | last post by:
Does the redirect statement: header(Location:"http://www.newpage.com"); need to come before certain statements? I've setup a login page and try to redirect a user once they have logged in...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
5
by: nasse | last post by:
I am getting the following error msg whenever I try to login. I tried to turn my output_buffering = On in my php.ini but is not working for me. Would you please help me: Warning: Cannot modify...
8
by: mcserret | last post by:
I know this is a recurring problem that has been addressed here before, but even after reading all that has gone before, I am still stumped. I have a form that is designed to send data to a PHP...
2
by: smartic | last post by:
I'm having problem with header redirection that is my code: <?php header("location:Redirecting.php"); exit; ?> //Then the HTML It give me an error
3
by: webandwe | last post by:
hi, For some reason the URLS won't redirect, it has worked but now it does not want to work. I even got the script from scratch again but still it does not want to work. I get the following...
3
by: gubbachchi | last post by:
Hi, I have written php code to retrive the image from mysql and display it on the webpage. Here is the code <?php require_once("DBConnect.php"); $gotten = @mysql_query("select user_photo from...
10
by: jessica87 | last post by:
hi there, i m using this coding to retrieve the file from database so that my user can download the file... <?php if (!isset($_GET)) die('Invalid Parameter'); include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.