Warning Messages Using Session Control

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

    Warning Messages Using Session Control

    I added session control to my survey application. I want to retain the
    person's name entered on the 1st page and use it as a variable value on
    subsequent pages.

    I added on the first script:

    <?
    session_start() ;
  • ZeldorBlat

    #2
    Re: Warning Messages Using Session Control

    Once output has been sent to the browser headers cannot be sent.
    Sending headers is how cookies are set (like session cookies), so you
    get the errors described.

    Somewhere in your script before session_start() you're sending output
    to the browser. In fact, the error message even tells you the file and
    line number where the output was sent (although in your post you cut
    that part out).

    Check the code listed in the error message. Even sending a single
    blank space counts. You can ensure that no output is sent before
    calling session_start() by using ob_start() and ob_flush() -- although
    the correct solution is to probably rearrange your script so
    session_start() gets called earlier on.

    Comment

    • Colin McKinnon

      #3
      Re: Warning Messages Using Session Control

      bobkaku wrote:
      [color=blue]
      >
      > I added on the first script:
      >
      > <?
      > session_start() ;
      > .
      > .
      > .
      > session_registe r($MyVar);
      >[/color]

      Don't use session_registe r - reference a mamber of the $_SESSION array
      directly e.g.

      print $_SESSION['MyVar'];

      Otherwise your code will only work if register_global s is on (nothing to do
      with the error messages you were getting - see Zeldor's response)

      C.

      Comment

      Working...