[RESOLVED] Warning: session_start(): Cannot send session cookie - headers already sent - Page 3
Page 3 of 3 FirstFirst 123
Results 31 to 42 of 42

Thread: [RESOLVED] Warning: session_start(): Cannot send session cookie - headers already sent

  1. #31
    Junior Member
    Join Date
    Sep 2012
    Posts
    7

    hmm..

    nobody with an idea based on my code?

  2. #32
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    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.)

  3. #33
    Junior Member
    Join Date
    Sep 2012
    Posts
    7
    I uploaded the script to another server so you can see the result..

    http://mywebproof.com/test/home.php

    is it weird that when you goto the actual 'login.php' file it doesn't show the error, but when other pages pull it in, it does?

  4. #34
    Junior Member
    Join Date
    Sep 2012
    Posts
    7
    NOTE: my link above didn't copy in the www. and i can't edit...i guess no privledges for that yet either =/

    any help or suggestions appreciated

  5. #35
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    Two things:

    1. 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.
    2. 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).

  6. #36
    Junior Member
    Join Date
    Sep 2012
    Posts
    7
    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!


    Quote Originally Posted by bradgrafelman View Post
    Two things:

    1. 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.
    2. 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).

  7. #37
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    Quote Originally Posted by jschnyderite View Post
    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.

    Quote Originally Posted by jschnyderite View Post
    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).

    Quote Originally Posted by jschnyderite View Post
    Sorry, I'm not a programmer
    Which begs the question: Why are you trying to program, then?

  8. #38
    Junior Member
    Join Date
    Sep 2012
    Posts
    7
    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.

    Quote Originally Posted by bradgrafelman View Post
    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

  9. #39
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    Quote Originally Posted by jschnyderite View Post
    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.

    Quote Originally Posted by jschnyderite View Post
    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).

  10. #40
    Junior Member
    Join Date
    Sep 2012
    Posts
    7
    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?

    Quote Originally Posted by bradgrafelman View Post
    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).

  11. #41
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    Quote Originally Posted by jschnyderite View Post
    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.

    Quote Originally Posted by jschnyderite View Post
    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.

  12. #42
    Junior Member
    Join Date
    Jun 2012
    Posts
    4

    its work !!!

    Quote Originally Posted by NogDog View Post
    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
    (-:

Thread Information

Users Browsing this Thread

There are currently 4 users browsing this thread. (0 members and 4 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •