SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Breaking Session

    include 'temp107h.php'; continues the session

    header('Location: http://localhost/temp107h.php'); breaks the session.

    How can I use header() and not break the session?

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    session_start(); re-activates the session even without session_write_close().

    then, what's the advantage of using use session_write_close()?

  3. #3
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,332
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    "...header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP."

    From PHP.net (the first place to look for answers).
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I found session_write_close() in the manual. I used it thinking it would store my session array, but all it needed was session_start(); in the script called in the header to get access to the session array again.

    I just wanted continued access to the session array and I thought it would be proper to close the session array with session_write_close() before re-opening it with session_start().

    why should session_write_close() matter when using session_start() continues to give me access to the session array?

  5. #5
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nichemtktg View Post
    session_start(); re-activates the session even without session_write_close().

    then, what's the advantage of using use session_write_close()?
    session_write_close writes the session back to the session file and releases it so that another instance of your php script can access it. This is handy for example if you have a script that may take a while to complete (such as a download script) which no longer needs access to the session. In this scenario if you didn't use session_write_close and you tried to call another script which uses session_start() then you would just see the browsers blue bar moving slowly as it heads towards a timeout. This is because session_start() cannot gain control of the session and effectively ends up in a queue.

    It's kind of like using a Critical Section in win32 languages.
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.


Bookmarks

Posting Permissions

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