Warning: Cannot modify header information

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ruteckyb
Forum Newbie
Posts: 6
Joined: Thu Feb 05, 2009 12:45 am

Warning: Cannot modify header information

Post 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
{}
?>
 
Last edited by ruteckyb on Thu Feb 05, 2009 7:56 am, edited 4 times in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Warning: Cannot modify header information

Post 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]
ruteckyb
Forum Newbie
Posts: 6
Joined: Thu Feb 05, 2009 12:45 am

Re: Warning: Cannot modify header information

Post by ruteckyb »

Anyone have anything to say other than a stupid remark about how I formatted my message?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Warning: Cannot modify header information

Post 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.
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: Warning: Cannot modify header information

Post by Skoalbasher »

You say there's not "echo output".

I don't see an echo statement anywhere in there.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Warning: Cannot modify header information

Post by Benjamin »

I also don't see a header redirect in there either.
ruteckyb
Forum Newbie
Posts: 6
Joined: Thu Feb 05, 2009 12:45 am

Re: Warning: Cannot modify header information

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Warning: Cannot modify header information

Post 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.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Warning: Cannot modify header information

Post 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.
ruteckyb
Forum Newbie
Posts: 6
Joined: Thu Feb 05, 2009 12:45 am

Re: Warning: Cannot modify header information

Post 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?
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Warning: Cannot modify header information

Post 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.
ruteckyb
Forum Newbie
Posts: 6
Joined: Thu Feb 05, 2009 12:45 am

Re: Warning: Cannot modify header information

Post 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.
Post Reply