SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    May 2001
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    keep user logged in?

    hey,
    whats the best way to keep a user logged in? I am creating a shopping cart and i am storing there session information in a database. However, I do I keep them permanently logged in until they log out?

    thanks
    unregistered1

  2. #2
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    by far the easiest way is to use a cookie with the users information.. if its set they are logged in, if not then they are not logged in.. you can integrate that into sessions so that way when they first log in, you can set session variables for username and password.. then set the same info into a cookie.. When a user ends his/her session, the session variables will be unset.. therefore for security, if they do not have session username/password set, check the db with the cookie info to make sure its valid. that way you do not need to check there user/pw on each page


    this is actually just a thought, anyone else can feel free to offer bette/other ways..

    there is a class called access_user you can find here:
    http://phpclasses.spunge.org/browse/package/1906.html

    i updated it a whole bunch to suite my needs, but its fairly well written and easy to use.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2005
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I am understanding you right, you just want their cart to remain the same even if they close their browser and return to your site at a later point. The only way I can think of that can do this is to store their session in your db and in a cookie on their computer. You will also have to log their ip since some users will clear their cookies or have them disabled.

  4. #4
    SitePoint Addict
    Join Date
    May 2001
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    chowmein, thats exactly what i want to do... I am just contemplating on what I want to store in the database. the session id, customer id and the shopping cart information...

    the cookie will probably just store an md5 of the session id...

    thanks
    unregistered1.

  5. #5
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just remember that working with someones ip isnt all that safe since there are many different computers that connect via the same public ip.

  6. #6
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wrong post
    Last edited by _matrix_; May 25, 2005 at 15:06.


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
  •