session

Discussion in 'PHP' started by subha rr, Jul 30, 2008.

  1. #1
    Hi...

    What is a session? Where do we use it?

    subha
     
    subha rr, Jul 30, 2008 IP
  2. yleiko

    yleiko Peon

    Messages:
    74
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    session is something you set when a visitor enters your page and stays same until your visitor leaves your web page(or you change it).

    It is basically used to track user behavior.
    It is key point for user logins. When your visitor logins with his/her username and password, you assign a value into the session and through that value you know that the user is logged, while your user crawls between pages in your site.
    Otherwise you 'd ask username/password at every page.
     
    yleiko, Jul 30, 2008 IP
  3. garrettheel

    garrettheel Peon

    Messages:
    341
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yep, basically what yleiko said. Here's an example of it in use.

    (in your login script after you authorize the user)

    $_SESSION['username'] = 'Fred';

    (then on your welcome page)

    echo "Welcome, " . $_SESSION['username'];
     
    garrettheel, Jul 30, 2008 IP