Results 1 to 5 of 5

Thread: Noob Question

  1. #1
    Join Date
    Oct 2006
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Noob Question

    Call me a noob. It's true.

    How exactly does the session_start and other such functions work? I'm sure it's incredibly obvious, but I'm kinda strapped for time and resources.

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    you need to declare the session at the very top of your page before anything is parsed / the session variables used
    Code:
    <?php 
    session_start();
    
    $_SESSION['user'] = $_SERVER['USER_AGENT'];
    ?>

  3. #3
    Join Date
    Oct 2006
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks, embarrassed.

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    don't be... it wasnt too long ago that I had the very same question. thats the beauty of learning; we dont start with all the knowledge in the world

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    session_start() must be called before anything else on the page (ie output). To continue the session (at least to be sure it continues) you must include session_start() on every related page on the site.

    Once the session is enabled, $_SESSION[...] will be available on any page and data will be carried through continuously. It will expire after perhaps 15 minutes of inactivity, closing the browser, etc. A "session" describes it well.

    To end a session, it's a bit harder-- look at session_destroy() and related functions on php.net.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •