new at sessions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • edward hage

    new at sessions

    Hello, I am using PHP 4.3.1 with register_global s off.

    I want to pass information from one page to another and want to start a
    session for this using: session_start() at the beginning of my page
    searchresult.ph p

    However, I get the following error:

    Warning: session_start() [function.sessio n-start]: Cannot send session
    cookie - headers already sent by (output started at
    /srv/www/htdocs/searchresult.ph p:7) in /srv/www/htdocs/searchresult.ph p
    on line 8

    Warning: session_start() [function.sessio n-start]: Cannot send session
    cache limiter - headers already sent (output started at
    /srv/www/htdocs/searchresult.ph p:7) in /srv/www/htdocs/searchresult.ph p
    on line 8

    A session_ID is created but any $_SESSION['variable'] I define is not
    recognised. What am I doing wrong??

    Thanks in advance,
    Edward

  • Leslie Hoare

    #2
    Re: new at sessions


    "edward hage" <edha@xs4all.nl > wrote in message
    news:3fd31c70$0 $201$e4fe514c@n ews.xs4all.nl.. .[color=blue]
    > Hello, I am using PHP 4.3.1 with register_global s off.
    >
    > I want to pass information from one page to another and want to start a
    > session for this using: session_start() at the beginning of my page
    > searchresult.ph p
    >
    > However, I get the following error:
    >
    > Warning: session_start() [function.sessio n-start]: Cannot send session
    > cookie - headers already sent by (output started at
    > /srv/www/htdocs/searchresult.ph p:7) in /srv/www/htdocs/searchresult.ph p
    > on line 8
    >
    > Warning: session_start() [function.sessio n-start]: Cannot send session
    > cache limiter - headers already sent (output started at
    > /srv/www/htdocs/searchresult.ph p:7) in /srv/www/htdocs/searchresult.ph p
    > on line 8
    >
    > A session_ID is created but any $_SESSION['variable'] I define is not
    > recognised. What am I doing wrong??
    >
    > Thanks in advance,
    > Edward
    >[/color]

    you have to call ob_start() before any other output, including spaces. so
    put it right at the top of the page, and it should work ok.


    Leslie


    Comment

    • edward hage

      #3
      Re: new at sessions

      Leslie Hoare wrote:[color=blue]
      > "edward hage" <edha@xs4all.nl > wrote in message
      > news:3fd31c70$0 $201$e4fe514c@n ews.xs4all.nl.. .
      >[color=green]
      >>Hello, I am using PHP 4.3.1 with register_global s off.
      >>
      >>I want to pass information from one page to another and want to start a
      >>session for this using: session_start() at the beginning of my page
      >>searchresult. php
      >>
      >>However, I get the following error:
      >>
      >>Warning: session_start() [function.sessio n-start]: Cannot send session
      >>cookie - headers already sent by (output started at
      >>/srv/www/htdocs/searchresult.ph p:7) in /srv/www/htdocs/searchresult.ph p
      >>on line 8
      >>
      >>Warning: session_start() [function.sessio n-start]: Cannot send session
      >>cache limiter - headers already sent (output started at
      >>/srv/www/htdocs/searchresult.ph p:7) in /srv/www/htdocs/searchresult.ph p
      >>on line 8
      >>
      >>A session_ID is created but any $_SESSION['variable'] I define is not
      >>recognised. What am I doing wrong??
      >>
      >>Thanks in advance,
      >>Edward
      >>[/color]
      >
      >
      > you have to call ob_start() before any other output, including spaces. so
      > put it right at the top of the page, and it should work ok.
      >
      >
      > Leslie
      >
      >[/color]
      I tried ob_start(); before session_start() ; but that did not help.

      I also don't see why the connection between buffering output and a
      session. Could anyone explain more about that?

      Greetings, Edward

      Comment

      • Shawn Wilson

        #4
        Re: new at sessions

        edward hage wrote:[color=blue]
        >
        > Leslie Hoare wrote:[color=green]
        > > "edward hage" <edha@xs4all.nl > wrote in message
        > > news:3fd31c70$0 $201$e4fe514c@n ews.xs4all.nl.. .
        > >[color=darkred]
        > >>Hello, I am using PHP 4.3.1 with register_global s off.
        > >>
        > >>I want to pass information from one page to another and want to start a
        > >>session for this using: session_start() at the beginning of my page
        > >>searchresult. php
        > >>
        > >>However, I get the following error:
        > >>
        > >>Warning: session_start() [function.sessio n-start]: Cannot send session
        > >>cookie - headers already sent by (output started at
        > >>/srv/www/htdocs/searchresult.ph p:7) in /srv/www/htdocs/searchresult.ph p
        > >>on line 8
        > >>
        > >>Warning: session_start() [function.sessio n-start]: Cannot send session
        > >>cache limiter - headers already sent (output started at
        > >>/srv/www/htdocs/searchresult.ph p:7) in /srv/www/htdocs/searchresult.ph p
        > >>on line 8
        > >>
        > >>A session_ID is created but any $_SESSION['variable'] I define is not
        > >>recognised. What am I doing wrong??
        > >>
        > >>Thanks in advance,
        > >>Edward
        > >>[/color]
        > >
        > >
        > > you have to call ob_start() before any other output, including spaces. so
        > > put it right at the top of the page, and it should work ok.
        > >
        > >
        > > Leslie
        > >
        > >[/color]
        > I tried ob_start(); before session_start() ; but that did not help.
        >
        > I also don't see why the connection between buffering output and a
        > session. Could anyone explain more about that?[/color]



        session_start() sends a cookie to the user's browser. Cookies must be sent in
        the header. You cannot send headers once you start to send content, even a
        single space or linebreak. The solution, then, is to put session_start() at the
        top of your file, if possible.

        This works:
        -------------- START OF FILE ------------------
        <?PHP
        session_start() ;
        ?>
        -------------- END OF FILE ------------------

        This doesn't work because it outputs a blank line before the cookie is sent:
        -------------- START OF FILE ------------------

        <?PHP
        session_start() ;
        ?>
        -------------- END OF FILE ------------------


        You don't need ob_start() to use sessions. It can be helpful, though, if you
        need to output text before you call session_start() . It sticks the text in a
        buffer, effectively delaying sending it until after session_start() sends the
        cookie.

        This works because it delays sending outputted text until after the cookie is
        sent:
        -------------- START OF FILE ------------------
        <?PHP
        ob_start();
        ?>

        Hello World.

        <?PHP
        session_start() ;
        ob_flush();
        ?>
        -------------- END OF FILE ------------------

        Regards,
        Shawn

        --
        Shawn Wilson
        shawn@glassgian t.com

        Comment

        Working...