Session Problem

Discussion in 'PHP' started by SupernalMedia, Mar 27, 2008.

  1. #1
    I am getting these errors...

    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/seraphic/public_html/index.php:1) in /home/seraphic/public_html/index.php on line 1

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/seraphic/public_html/index.php:1) in /home/seraphic/public_html/index.php on line 1

    I know that your supposed to put session_start(); before any output to the browse even white space but for some reason I still get these errors. Also, I made sure session_start(); doesn't appear in any of the includes or anywhere else in the file and it doesn't... This is what the top of my document looks like..

    
    <?php
    session_start();
    include("config.php");
    
    Code (markup):
    http://www.seraphicgaming.com
     
    SupernalMedia, Mar 27, 2008 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Does this file contain utf8 characters?
     
    mwasif, Mar 27, 2008 IP
  3. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Does the file have any whitespace (new lines, etc.) before the '<?php'?
     
    TwistMyArm, Mar 27, 2008 IP
  4. SupernalMedia

    SupernalMedia Well-Known Member

    Messages:
    427
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #4
    No there is no new lines before twist, and mwasif, why would that mess it up?
     
    SupernalMedia, Mar 27, 2008 IP
  5. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #5
    Make sure <?php session_start(); ?> is the VERY first thing that appears on your website. If you have any code on your pages which is outputting to the browser before this function call then you'll get the error you've described.
     
    Weirfire, Mar 27, 2008 IP
  6. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #6
    Yes, sometimes it mess up. I had a PHP script which get all the content starting from <? till the last line and rewrite everything to the file. Just doing it resolved the problem. You can also create such a script or use some other editor to remove these characters. Binary editors may be of some help.
     
    mwasif, Mar 27, 2008 IP
  7. SupernalMedia

    SupernalMedia Well-Known Member

    Messages:
    427
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #7
    Yes Weir, it is the very first thing, nothing is before it, like I posted above it looks like this...

    <?php
    session_start();
    include("config.php");
    and so on...

    Anyways, mwasif there isn't I was just wondering, anyone else have any ideas?
     
    SupernalMedia, Mar 27, 2008 IP
  8. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #8
    open your config.php.. check there if there's a session_start() there and header function..
     
    bartolay13, Mar 27, 2008 IP
  9. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #9
    I was just thinking that very same thing :)
     
    Weirfire, Mar 27, 2008 IP
  10. SupernalMedia

    SupernalMedia Well-Known Member

    Messages:
    427
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #10
    There isn't a session_start(); in config or any header functions.
     
    SupernalMedia, Mar 27, 2008 IP
  11. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #11
    And the file where session_start() is displayed isn't an include of another file?

    It's very strange that the error appears AFTER a lot of the page has loaded which would suggest you are already displaying a lot of the page content before the session_start() function call.

    Is the file where session_start() appears "index.php"?
     
    Weirfire, Mar 27, 2008 IP
  12. SupernalMedia

    SupernalMedia Well-Known Member

    Messages:
    427
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #12
    No session_start(); is above every single thing in that file, again the top of the file looks like this...

    
    <?php
    session_start();
    include("config.php");
    // rest of the file
    
    Code (markup):
     
    SupernalMedia, Mar 27, 2008 IP
  13. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #13
    oh i see.. check the file
    (where <?php
    session_start();
    include("config.php");) is also included..

    this error is caused of writing the session_start() twice or not on the top
     
    bartolay13, Mar 27, 2008 IP
  14. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #14
    Do you have Dreamweaver?
     
    Weirfire, Mar 27, 2008 IP
  15. SupernalMedia

    SupernalMedia Well-Known Member

    Messages:
    427
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #15
    Yeah and it's not written anywhere else, and also it's not included twice and it's at the very top as well.
     
    SupernalMedia, Mar 27, 2008 IP
  16. SupernalMedia

    SupernalMedia Well-Known Member

    Messages:
    427
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #16
    Yes I do have dreamweaver.
     
    SupernalMedia, Mar 27, 2008 IP
  17. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #17
    Do an entire site search for "session_start()" and just make sure it's not displayed twice.

    PM me the FTP details if that doesn't pick up 2 function calls.
     
    Weirfire, Mar 27, 2008 IP
    SupernalMedia likes this.
  18. SupernalMedia

    SupernalMedia Well-Known Member

    Messages:
    427
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #18
    I did and there is no other occurrence of session_start() =/

    Can you contact me on one of the following Weir, thanks...

    MSN:
    AIM: xxmikyboixx
     
    SupernalMedia, Mar 27, 2008 IP
  19. SupernalMedia

    SupernalMedia Well-Known Member

    Messages:
    427
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #19
    Fixed...

    Last night I edited the file in notepad because I was being lazy, and apparently notepad changed the filetype to utf-8, I had to manually change it back to ANIS through dreamweaver, very weird, but fixed.

    (Thanks Weirfire for all the help, great guy!)
     
    SupernalMedia, Mar 27, 2008 IP
  20. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #20
    The file type of index.php was utf-8 for anyone who ever comes across this error in the future.

    Make sure your file is saved in ANSI format (Unicode might work as well)

    [This is seperate from the charset]


    [EDIT: Beat me to it ;) ]
     
    Weirfire, Mar 27, 2008 IP