SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: User Sessions

  1. #1
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    firstly, you'd need PHP4 support ..

    PHP4 has built in support for sessions..

    you'd start your session by putting in session_start() in the top of your script

    now, you can get the session id by doing something like $var = session_id();

    generally the session id variable is PHPSESSID .. this is sometimes changed on servers, to SESSID, etc ...

    you can find out what your session id variable is by running phpinfo(); on a script and looking through the server set variables

    you would pass your session on from 1 page to another by doing something in the form of
    echo "<a href=\"file.php?SESSID=$var\">";

    $var would be the session id itself and the word SESSID would be replaced by the variable found in phpinfo() ouput

    an EASY way is something as such:

    <?
    php script here
    ?>
    <a href="http://www.site.com/file.php?var1=value1&<?=SID?>">link text</a>
    <?
    more php code
    ?>

    the <?=SID?> would insert "SESSID=43!@#$RAFDAF@$W#VASDFASDF"

    SESSID is automatically figured out , etc

    also, when session_start() is initiated, it sends a cookie to the browser, so the session id is passed to the script automatically via the browser

    once your have a valid session started, you can set variables in the session with session_register("varname") and so on

    i suggest you goto www.php.net , hover your mouse over the "quick ref" and type in "sessions" .. read the detailed information on sessions in the docs

    sessions are quite advanced, however quite easy also once you get the hang of it

    hope that helps !
    -------------------------
    my PHP host

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Cork, Ireland
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I implement User Sessions using PHP/MySQL????

  3. #3
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    User sessions are just sophisticated use of cookies. If you want the session to time out you can write a cookie and either have it expire in x amount of time or read the cookie on every page (its sent anyways) to find out when it was created. If the difference is greater than time since last access allowed kick the user to a login page.

    ------------------
    Wayne Luke - Sitepoint Forums Administrator
    Digital Magician Magazine - MetaQuark Creations (Coming Soon)
    sitepoint@digitalmagician.com

  4. #4
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yeah well my way would work in PHP3 or PERL or even javascript for that matter.

    ASP also has built in support for Sessions, session tracking, and session variables.

    ------------------
    Wayne Luke - Sitepoint Forums Administrator
    Digital Magician Magazine - MetaQuark Creations (Coming Soon)
    sitepoint@digitalmagician.com


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
  •