Page 1 of 1

Warning: Cannot modify header information

Posted: Thu Feb 05, 2009 12:55 am
by ruteckyb
Ive racked my brains on this one. I removed the include so that is not the problem, and I have made sure there are no characters before the <?php , still I get an error. There is no echo output and I have reduced script to its bear minimum, sill error. Output is supposedly being started in line 1.

Code: Select all

 
<?php
mysql_connect("xxxxx", "xxxxx", "xxxxx") or die(mysql_error());
mysql_select_db("xxxxx") or die(mysql_error());
 
$Email = $_GET['Email'];
$Password = $_GET['Password'];
 
$result = mysql_query("SELECT * FROM members WHERE Email like '$Email' AND Password like '$Password'") 
or die(mysql_error());  
 
 
if ($num_results !="0") {
                        $row = mysql_fetch_array($result);
                        $num_results = mysql_num_rows($result);
            setcookie('MemberNumber',$Number);  
            }
    else
{}
?>
 

Re: Warning: Cannot modify header information

Posted: Thu Feb 05, 2009 12:56 am
by Benjamin
ruteckyb, Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]

Re: Warning: Cannot modify header information

Posted: Thu Feb 05, 2009 10:23 pm
by ruteckyb
Anyone have anything to say other than a stupid remark about how I formatted my message?

Re: Warning: Cannot modify header information

Posted: Thu Feb 05, 2009 10:33 pm
by Benjamin
Yes, if you are absolutely positive that there is nothing in front of your opening PHP statement, your editor is most likely placing an invisible character there.

And, you'll most likely catch flac here anytime you post code without using

Code: Select all

 tags.  It drives us nuts.

Re: Warning: Cannot modify header information

Posted: Thu Feb 05, 2009 10:47 pm
by Skoalbasher
You say there's not "echo output".

I don't see an echo statement anywhere in there.

Re: Warning: Cannot modify header information

Posted: Thu Feb 05, 2009 10:49 pm
by Benjamin
I also don't see a header redirect in there either.

Re: Warning: Cannot modify header information

Posted: Fri Feb 06, 2009 1:02 am
by ruteckyb
astions wrote:Yes, if you are absolutely positive that there is nothing in front of your opening PHP statement, your editor is most likely placing an invisible character there.

And, you'll most likely catch flac here anytime you post code without using

Code: Select all

 tags.  It drives us nuts.[/quote]

Thanks for pointing that out at the same time as you post a response to the question, that is a very efficient  way to do it. I will be sure to do so in the future.

Wrote this in notepad so Im sure there is nothing prior to the <?php

As to the other posts, as I said I removed all the echo statements as well as the header include to see if one of those were causing the problem. Interesting enough if I comment out everything except the php start/stop and the cookie function I STILL get the error.

I think I will write the script again to see if there isnt some hidden text prior to the <?php

Re: Warning: Cannot modify header information

Posted: Fri Feb 06, 2009 1:18 am
by Benjamin
If there are any PHP warnings or notices being sent by your code, that will count as output and you can no longer send headers. You can enable output buffering in php.ini as a bandaid fix if nothing else, but it would be best for you to figure out what exactly is sending output.

Re: Warning: Cannot modify header information

Posted: Fri Feb 06, 2009 1:36 am
by susrisha
comment out the set_cookie line and see the output..If you are getting any errors prior to the statement, it will be printed out. I see that the $num_results variable is not yet initialised and its being used. might be the problem.

Re: Warning: Cannot modify header information

Posted: Fri Feb 06, 2009 6:19 pm
by ruteckyb
That didnt work. Here is a mind trip.

Code: Select all

 
<?php
            setcookie('MemberNumber',$Number);  
?>
 
Produces this error.
Warning: Cannot modify header information - headers already sent by (output started at /home/content/s/e/l/sellfivesevenz/html/logmein.php:1) in /home/content/s/e/l/sellfivesevenz/html/logmein.php on line 2

This means there must be some bites prior the the start of PHP? But how can I see them? Or delete them?

Re: Warning: Cannot modify header information

Posted: Fri Feb 06, 2009 8:41 pm
by susrisha
@ruteckyb
looking at both the codes that you have pasted, i see that the line 1 is left empty. but php considers it as "\n" character and hence displays the errors. try deleting the line or start the code straight from line one.

Re: Warning: Cannot modify header information

Posted: Sat Feb 07, 2009 12:15 am
by ruteckyb
Thats just a space I left between to code tags on this forum by mistake. Sorry about that. There is no blank line in the file.