473,386 Members | 1,738 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,386 software developers and data experts.

HELP with headers already sent

I am getting the following error when i try to log on to my data base
Expand|Select|Wrap|Line Numbers
  1. Warning: session_register() [function.session-register]: Cannot send session cookie - headers already sent by (output started at D:\virtualservers\182763\root\test\login\checklogin.php:1) in D:\virtualservers\182763\root\test\login\checklogin.php on line 18
  2.  
  3. Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at D:\virtualservers\182763\root\test\login\checklogin.php:1) in D:\virtualservers\182763\root\test\login\checklogin.php on line 18
  4.  
  5. Warning: Cannot modify header information - headers already sent by (output started at D:\virtualservers\182763\root\test\login\checklogin.php:1) in D:\virtualservers\182763\root\test\login\checklogin.php on line 20
  6.  
  7. Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0
  8.  
the code i have is
[php]
<?php

include('vistacconfig.php');

// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register('myusername');
session_register('mypassword');
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}

ob_end_flush();
?>
[/php]

i cannot find the error and the more i look the more i caannot see

can any body help me please

thanks
Feb 24 '08 #1
4 1720
ronverdonk
4,258 Expert 4TB
Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

moderator
Feb 24 '08 #2
ronverdonk
4,258 Expert 4TB
Probably some data was already sent (maybe in your include script). I will show the text of an article by wildteen88, june 2006, who can explain this a lot better then I can.
The reason why you are getting this message is because you have may have/be:
  • Whitespace before the opening php tag <?php
  • Outputting something to the browser before you use session_start, header, setcookie etc
session_start, setcookie, header and a few other functions write header information to the web server/browser what to do. Such as when you use session_start it requests the browser to create a cookie which stores the PHPSESSID.

If you have output before you use these functions then they are unable to send new header information as it has already been sent in the form text/html, and so you get the headers already sent error message.

You can easily find the source of the problem by looking at the error message. As the answer is actully in there, but most people dont notice it as they may not understand what the error means. So lets take this error message as an example:

Warning: Cannot modify header information - headers already sent by (output started at C:\server\www\test.php:6) in C:\server\www\test.php on line 8
Now PHP has given us a clue here as it has told use where the output has started! Have look where it says output started at and it gives you the full path to the file and the line number. Now the line number that it stats is not usually where the output has started but where the output has ended, becuase the output could be above that line.
So lets look at test.php:
Expand|Select|Wrap|Line Numbers
  1.  1 <html>
  2.  2 <head>
  3.  3 <title>Header test</title>
  4.  4 </head>
  5.  5 <body>
  6.  6 <?php
  7.  7
  8.  8 header("Location: http://www.google.com");
  9.  9
  10. 10 ?>
  11. 11 </body>
  12. 12 </html>
As you can see line 6 is the opening PHP tag (< ?php) this isn't the output but look above that line you'll notice it has some HTML code. This html code is the cause of the error!

So when you get this error message again look for the clue where it says output started at and goto the file and line number it says. Look above the line number and find where your output is located to.

Hope that helps you understand why your are getting this error message. (Thanks to wildteen88)
Ronald
Feb 24 '08 #3
i have checked out my files and i cannot fine the error
as per the post the error says it is on line 1 which is the start of my file
it still has me stumped

i am a newbie to php and all i am trying to do is create a login to a database

can you rhelp me with the scritpt i need
i thought the script i had would work but it keeps gieving me the errors stated above
and i also apolosgise for not postin gin the correct format

i will try and do it correctly form now on
Feb 24 '08 #4
ronverdonk
4,258 Expert 4TB
Are you sure you do not send anything out in the first line? Implicitly, maybe a blank character right after the <?php, because that is also a char out.

Ronald
Feb 24 '08 #5

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

Similar topics

6
by: Lochness | last post by:
I'm hoping someone can help me with this. I've seen and tried various solutions I've seen on the net, but nothing works. Of course it works perfectly on localhost, but when I upload it to the...
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...
2
by: Nabeelah Ali | last post by:
session_start() session_destroy(); echo "<center><font color=red>You are now logged out!</strong></font></center><br />"; header("Location: index.php"); Can somebody tell me why this bit of...
5
by: Philip Ronan | last post by:
OK, here's my 2p worth: === Q. Why am I getting the error message 'Headers already sent'? A. PHP produces this error message when you try to set a header for a web page after you have already...
6
by: Andreas Klemt | last post by:
Hello, I get this error Message "cannot redirect after http headers have been sent" when I do this response.redirect ("home.aspx") How can I find out with vb.net if already a http header has...
22
by: Platero | last post by:
Hi, I've a stupid question but... The code is the following: if(($role!='tutor')&&(array_key_exists('tutor_id',$_GET))) { $possible_ids = array(2,6,7,8,9,10); $t_id = $_GET;
2
by: Comcast | last post by:
I am using a form that uses PHP to create an e-mail and send it off. When the script runs, I get an error page, although the e-mail is sent off. The error I am getting is: Warning:...
2
mideastgirl
by: mideastgirl | last post by:
Warning: session_start() : Cannot send session cookie - headers already sent by (output started at /home/content/m/i/d/mideasthonors/html/adminloginprocess.php:1) in...
6
Markus
by: Markus | last post by:
Things to discuss: Headers What are they? What does PHP have to do with headers? Why can they only be sent before any output? Common causes
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.