Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Re: session_start()

    Ian.H [dS] wrote:
    > -----BEGIN PGP SIGNED MESSAGE-----
    > Hash: SHA1
    >
    > Whilst lounging around on 11 Jul 2003 07:51:58 -0700,
    > [email]skywalker2070@hotmail.com[/email] (sky2070) amazingly managed to produce the
    > following with their Etch-A-Sketch:
    >
    >> i am trying to session_start() function in my code but the server
    >> return
    >>
    >> Warning: session_start() [function.session-start]: Cannot send
    >> session cookie - headers already sent by (output started at
    >> C:\Program
    >> Files\Apache Group\Apache2\htdocs\sessionstart.php:9) in C:\Program
    >> Files\Apache Group\Apache2\htdocs\sessionstart.php on line 11
    >>
    >> Warning: session_start() [function.session-start]: Cannot send
    >> session cache limiter - headers already sent (output started at
    >> C:\Program Files\Apache Group\Apache2\htdocs\sessionstart.php:9) in
    >> C:\Program Files\Apache Group\Apache2\htdocs\sessionstart.php on
    >> line 11
    >>
    >> can anyone point out where is the error?
    >
    >
    > Yes.. on line 11 ;)
    >
    > On a more serious note.. session_start() should be the first call in
    > your script (well above any output ever occurs).. hence you get the
    > "headers alrady sent" as by the time you're calling session_start()
    > (which is a header value), it's already displaying the "body" =)
    >
    >
    >
    > Regards,
    >
    > Ian
    >
    > -----BEGIN PGP SIGNATURE-----
    > Version: PGP 8.0
    >
    > iQA/AwUBPw7QrWfqtj251CDhEQKhYgCggA4PnS8z16i0B1e9dc5Tb7 v3Ip4An2pl
    > tOQsMnFzbOkkEBfejIUKMSNX
    > =yQJy
    > -----END PGP SIGNATURE-----
    Just one clarification for the original poster, as I think this still might
    be semi-unclear to him. (Had he understood the manual he would not be asking
    this question, so obviously a very detailed answer is required since the
    manual entry for session_start() is VERY clear.)

    session_start() must come before *any* output. That means that if your file
    is like this:
    <start of file>
    <blank line>
    <?php
    session_start();
    ....
    you've got a problem. The blank line starts the output, and sends headers.
    session_start() must come before any and all output. (It need not
    *necessarily* be the first call, but this is usually a good practice, as
    this will ensure there is no output before it..) So use:

    <start of file>
    <?php
    session_start();
    ....

    and you should have no problems.

    // Ian Fette


    Agelmar Guest

  2. Similar Questions and Discussions

    1. Help with session_start()
      Hi. I was tring to start a session my web page and tried using the session_start(). However i keep gettin the warning: Warning: session_start()...
    2. Session_Start not firing
      I'm workinbg in Visual Studio 2003. I'm experimenting with creating a session variable, and from all I can gather. the Session_Start event is not...
    3. Classes and session_start()
      Hello there! I'm building a php system where I can put images in a zipfile and download it. I found some code to do this and created zip.php, a...
    4. session_start() problem
      * Thus wrote Jeff McKeon (com): Not related to your problem but: > session_regisister("userid", "userpassword"); spelling ~~~^^^^^^^^^^
    5. About Session_Start() with different Browser
      Hi all, I am new to php. At first, I wrote a php script to generate a pdf file from a tex file and load that pdf file to the browser by call a...
  3. #2

    Default session_start()

    Hi,

    I am working on a project where I need global variables to pass through
    some files.
    To achieve this, I am using session_start()in all files where global
    vars are needed..
    I am aware of the fact that I have to omit every output before I use
    session_start().
    However, still I receive error messages like:

    " Warning: session_start(): Cannot send session cookie - headers already
    sent by (output started at/home/www/123.freefronthost.com/header.html:9)
    in /home/www/123.freefronthost.com/extrins.php on line 2"

    and:

    "Warning: session_start(): Cannot send session cache limiter - headers
    already sent (output started at
    /home/www/123.freefronthost.com/header.html:9) in
    /home/www/123.freefronthost.com/extrins.php on line 2"

    Scripts that need session_start() to assign values to the global vars,
    always look like this (in 'header.html' I've included the html header info):


    01 <?php
    02 session_start();
    03 $MyGlobalVar=$_SESSION['MyGlobalVar'];
    04 include('header.html');
    05 include('somethingelse.inc');
    ...
    nn ?>

    What should I do to fix the errors/warnings?

    Thanks very much in advance!
    Best regards, Kees Epema
    cwepema Guest

  4. #3

    Default Re: session_start()


    Buffer all output with ob_start() / ob_get_contents() and write it to a
    file. Then download the file to see exactly what is written to the
    browser.

    ---
    Steve

    Steve Guest

  5. #4

    Default Re: session_start()

    .oO(cwepema)
     

    What is on the above mentioned lines?

    Micha
    Michael Guest

  6. #5

    Default Re: session_start()

    Steve wrote:
     

    ....won't solve problem if there is an auto-prepend set in the ini file.

    C.
    Colin Guest

  7. #6

    Default Re: session_start()

    X-No-Archive: yes
     
    file.

    OK, but it was not intended to solve the problem but to add
    information.

    If phpinfo() does says there's an auto_prepend_file, well there's an
    ideal place to stick an ob_start() 8-)

    ---
    Steve

    Steve Guest

  8. #7

    Default Re: session_start()

    treefrog wrote: 
    >
    >
    > Make sure there is absolutely no white space before the initial <? or <?php
    > tag. Even a single space messes it up. To debug it, look at the HTML source
    > and see what is before your first error message. Chances are though, that
    > it's the phantom space.
    >
    > Nathan
    >
    >[/ref]

    Thanks to you all!

    After all the problem was solved by something stupid simple:

    The form that generates the POST vars, had to check validity of a date.
    Therefore I made an include (chkDate.php)in which I also included the
    'header.html' file.
    After chkDate.php the actual page ('extrins.php') showed up, with the
    error messages as initially described.
    I deleted the ínclude('header.html') from the 'chkDate.php' file
    and...problem solved.
    Sorry for disturbing you all, but thanks for your help! I hope somebody
    benefits anyhow from the problem!
    Best regards, Kees Epema
    cwepema Guest

  9. #8

    Default Re: session_start()

    "cwepema" <nl> wrote in message
    news:qCXGd.8253$lga... 

    Make sure there is absolutely no white space before the initial <? or <?php
    tag. Even a single space messes it up. To debug it, look at the HTML source
    and see what is before your first error message. Chances are though, that
    it's the phantom space.

    Nathan


    treefrog Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139