Can you upload the script somewhere that we can download it and examine the file directly? (I would suggest attaching it to your next post, but I don't believe you have that ability yet since you're a new user.)
I asked if you could provide the file for download so that we can look at the actual PHP code. There's no way we can do that by just viewing the rendered output of that file.
Providing that link actually did provide insight. Read the error message again - the problem is not on line 1 of login.php. In fact, the real source of the error isn't even in login.php at all - it's inside home.php.
You can't output any data before you attempt to modify the HTTP headers (which is what session_start() tries to do when you propagate the session ID via a cookie).
Do you see anything within the home.php page that would cause that? the only line of code in the actual page is this:
<?php include('login.php'); ?>
Line 1 of that page is the DOCTYPE declaration. Sorry, I'm not a programmer, so the answer may be really basic. Appreciate you looking at this though!
Originally Posted by bradgrafelman
Two things:
I asked if you could provide the file for download so that we can look at the actual PHP code. There's no way we can do that by just viewing the rendered output of that file.
Providing that link actually did provide insight. Read the error message again - the problem is not on line 1 of login.php. In fact, the real source of the error isn't even in login.php at all - it's inside home.php.
You can't output any data before you attempt to modify the HTTP headers (which is what session_start() tries to do when you propagate the session ID via a cookie).
Do you see anything within the home.php page that would cause that?
I don't know, because you haven't shown us what the "home.php" file contains.
Originally Posted by jschnyderite
Line 1 of that page is the DOCTYPE declaration.
...which is data that PHP sends as output. Thus, you can't use session_start() after line 1 of home.php if that's the case.
Either restructure your code such that you can modify the HTTP headers if desired (e.g. any call to session_start(), header(), setcookie(), etc.), or do what I still consider to be a cheap workaround and enable output buffering (and set the limit high enough such that the buffer can contain all of the output you generate before trying to go back in time and output data that's to precede that output).
Originally Posted by jschnyderite
Sorry, I'm not a programmer
Which begs the question: Why are you trying to program, then?
Something is funny here..
I was just experimenting to see if I could figure out a fix.
This login was converted to another site a month or two ago and works fine...i copied a page from that which displays and works great on another server, and when I move it to the server where I'm having an issue - the same exact file displays the error.
I moved the <?php include('login.php'); ?> to the top of the document just for testing, and no errors...unfortunately, I need to align it in another spot on the page.
Originally Posted by bradgrafelman
I don't know, because you haven't shown us what the "home.php" file contains.
What is the best way to show you the raw files? zip it and put it on my server? email?
...which is data that PHP sends as output. Thus, you can't use session_start() after line 1 of home.php if that's the case.
Either restructure your code such that you can modify the HTTP headers if desired (e.g. any call to session_start(), header(), setcookie(), etc.), or do what I still consider to be a cheap workaround and enable output buffering (and set the limit high enough such that the buffer can contain all of the output you generate before trying to go back in time and output data that's to precede that output).
*GULP* This stuff is greek to me..
Which begs the question: Why are you trying to program, then?
im really just trying to fix something i inherited...believe me, i'd rather leave it to the pros =p
i copied a page from that which displays and works great on another server, and when I move it to the server where I'm having an issue - the same exact file displays the error.
Sounds like the "[other] server" has output buffering enabled (see the PHP manual section outcontrol for info; the PHP directive of interest would be output_buffering), whereas the server you're currently using does not.
Originally Posted by jschnyderite
I moved the <?php include('login.php'); ?> to the top of the document just for testing, and no errors...unfortunately, I need to align it in another spot on the page.
Restructuring your code is likely going to be more than just moving an include() statement around, since it sounds like the code was poorly written (e.g. design/layout is so heavily dominant that it supersedes the actual logic).
Thanks,
I'll look into when output buffering is enabled.
Is there anything I can look for in the code that would ensure that method is being used to store output?
I found no use of the phrase 'output_buffering' in code uploaded to the site...wasn't sure if this is just something set in the php.ini
if that comes up fruitless, what is the best way to get raw files to forum users to check out? - zip and upload? email?
Originally Posted by bradgrafelman
Sounds like the "[other] server" has output buffering enabled (see the PHP manual section outcontrol for info; the PHP directive of interest would be output_buffering), whereas the server you're currently using does not.
Restructuring your code is likely going to be more than just moving an include() statement around, since it sounds like the code was poorly written (e.g. design/layout is so heavily dominant that it supersedes the actual logic).
Is there anything I can look for in the code that would ensure that method is being used to store output?
If none of the ob_*() functions are used anywhere in the code, then you could always examine a phpinfo() printout to see what the PHP configuration looks like.
Originally Posted by jschnyderite
I found no use of the phrase 'output_buffering' in code uploaded to the site...wasn't sure if this is just something set in the php.ini
It can be enabled by default via a .ini configuration file, yes. That's why I linked you to "the PHP directive of interest" in my reply above.
The error message is specifically telling you that something on line 1 of the script generated output prior to the session_start() call. Either there is something before the opening <?php tag (a space, a newline, a unicode BOM character), or the only other thing I can think of would be if your PHP configuration has an auto_prepend_file specified and that file is generating output, although in that case I think the error message would point to that file instead (though I'm not 100% sure about that).
Therefore pending any further information, I suspect Weedpacket's suggestion is correct, that your editor is saving the file in UTF-8 with a BOM (byte order mark) at the start of the file. Either see if there is an option with your editor to save it as plain ASCII or as UTF-8 without the BOM, or else try another editor that can.
I had the same problam
and didnt know what to do ...
I tried out your solution with notepad++
and its absolutly works
(-:
Bookmarks