Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

AARRRGH annoying PHP error!

  • 22-05-2006 4:15am
    #1
    Closed Accounts Posts: 850 ✭✭✭


    Hey,

    Anyone have any ideas on this? I'm going mad...

    First line of my index.php script is...

    <?session_start();

    (I've tried it with a new line and a space.)

    I'm getting this error -

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

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

    I know this error message normally means some header information has already been sent, but how on earth can header information have already been sent when the very first thing I'm doing in the index.php file is starting the session?

    So annoying.

    Anyone???

    (PS note the time - 05:15 - this has been driving me mad all night!)


Comments

  • Registered Users, Registered Users 2 Posts: 3,514 ✭✭✭Rollo Tamasi


    i don't know if this the correct answer or not but you should have a space between the <? and the session : <? session_start(); ?>


  • Registered Users, Registered Users 2 Posts: 683 ✭✭✭Gosh


    If you have a blank line before the <? then this will be treated as output to the browser and therefore headers will already have been sent.

    Make sure the <? is the very first line in the php script.


  • Registered Users, Registered Users 2 Posts: 15,065 ✭✭✭✭Malice


    One other thing to check would be to make sure that the script that is generating the error isn't being included in another script. The including script might have already sent header information which would mean that even though your script looks fine and has "<?" on the first line, it will still cause an error.


  • Closed Accounts Posts: 8,478 ✭✭✭GoneShootin


    header output errors are almost always caused by the output_buffering. Set it to on in your php.ini :

    output_buffering = on


  • Registered Users, Registered Users 2 Posts: 2,170 ✭✭✭Serbian


    A Session has to be started before any output is sent to the browser. EG:

    [php]<?php

    // This is fine

    session_start();

    ?>[/php]

    Whereas:

    [php]
    <p>This is some html</p>

    <?php

    // This is not fine

    session_start();

    ?>[/php]

    Make sure you are not outputting printing anything or have any whitespace / HTML before the session_start. If you still can't sort it post some more code, or you can PM me and I can take a look if you don't want to post it to a public forum.


  • Advertisement
  • Closed Accounts Posts: 850 ✭✭✭DOLEMAN


    Hi,

    Thanks for the replies.

    Absolutely nothing is being called or written before the session_start().

    It is the first line in the page that is being called. There is no HTML output before it or includes.

    Very weird!

    I will try that output_buffering issue.

    Thanks.


  • Registered Users, Registered Users 2 Posts: 683 ✭✭✭Gosh


    Try changing
    <?session_start();
    
    to
    <?php
    session_start();
    


  • Closed Accounts Posts: 850 ✭✭✭DOLEMAN


    Yeah I've tried that.

    The funny thing is the other scripts on my server are working ok.

    A blank script, with only session_start() in it, is also causing this error.

    Weirdness... :(


  • Registered Users, Registered Users 2 Posts: 683 ✭✭✭Gosh


    Can you cut and paste the first 5 lines of index.php for let us see what it looks like


  • Registered Users, Registered Users 2 Posts: 683 ✭✭✭Gosh


    And how is index.php called - directly through the browser, indirectly by being the default page or is there a redirection to this page from something else?


  • Advertisement
  • Closed Accounts Posts: 850 ✭✭✭DOLEMAN


    Fixed it!

    This is bizarre. I checked index.php in vi and there were no visible special characters. I deleted (from the command line) index.php and retyped it in the exact same way.

    Now it works.

    I guess notepad must have been adding invisible characters?

    Actually, now that I think about it... I think I accidentely saved the index.php file with ANSI encoding rather that UTF-8. This might explain why the correct looking characters were actually incorrect!

    Hmmmm.

    Thanks for all the help!


  • Registered Users, Registered Users 2 Posts: 683 ✭✭✭Gosh


    (PS note the time - 05:15 - this has been driving me mad all night!)

    Well at least you can get some sleep tonight :D


  • Registered Users, Registered Users 2 Posts: 2,170 ✭✭✭Serbian


    Edit: Never mind. Typed this post almost an hour ago and forgot to submit it :p


Advertisement