Re: thoughts on sessions and members

From: Date: Fri, 03 Aug 2001 19:00:58 +0000
Subject: Re: thoughts on sessions and members
Groups: php.general 
Request: Send a blank email to php-general+get-61169@lists.php.net to get a copy of this message
You can use cookies to do this and just set a session cookie for however long they want to login for. Then if the time of the cookie's set time is xx from the current time, they cannot login (and it may be a good idea to set the member id in their cookie to a blank value). Another approach for this, which we use in YaBB, is to write log files (or you could write to a database) for each member. This log file is updated each time they visit, so that their user id, last time of visit, and other vital info are stored (such as how long they or we wish them to be logged in). This allows them to go on any PC and be autlogged in/out.. and also do not have to worry about cookies.. ' In YaBB, we still write a cookie to store their memberid and such, but you could implement it all via cookie or all via log files.. (sorry i am not thinking straight) > hey folks, hope the day is treating you well. > > here's a programming theory/methodology type question for y'all. i am > relatively new to programming and very new to object-oriented(ness). > > > suppose i have a site using sessions managed with an object $dog. $dog > contains a member object $dog->member and $dog->member contains a memberid > $dog->member->memberid. > > member information (username and encrypted password) are stored in a > database. > > > my index file begins > > require_once("dog.inc"); // this is where the objects get defined > session_start(); > session_register("dog"); > session_register("dog_member_id"); > if (!is_object($dog)) $dog = new dog; > > i can authenticate a user and carry that user along throughout the session > within $dog->member. a member can also logout, meaning that $dog- >member no > longer refers to them. when a member logs out, there is still a session and > valid $dog. > > so, what are the favored ways of allowing folks to auto-login? > > the approach i've taken is to set a cookie variable $dog_member_id. i assign > their memberid to the session variable $dog_member_id and within my index > file, i have > > if (!isset($HTTP_COOKIE_VARS["dog_member_id"])) { > if (isset($HTTP_SESSION_VARS["dog_member_id"])) { > setcookie("dog_member_id",$dog_member_id); > } > } > > then, i can check to see if $HTTP_COOKIE_VARS["dog_member_id"] is set when > someone visits my page by having this in my index. > > if ($HTTP_COOKIE_VARS["dog_member_id"] > 0) > $dog->member = new Member($HTTP_COOKIE_VARS["dog_member_id"]); > if ((!is_object($dog->member)) || (!$dog->member->is_member())) > $dog->member = new Member(-1); > > > whew! > > i had this all working in an older site not using objects, so i understand > the basics of what's going on. i also can get this to work if i check for > $HTTP_COOKIE_VARS["dog_member_id"] within my index file. > > i believe i also had this working at one time by checking for > $HTTP_COOKIE_VARS["dog_member_id"] within the dog object constructor, but of > course can't get that to work now :) > > is this a good approach? is it possible (should i want) to make this check > within the dog constructor? > > what are other approaches? > > thanks everyone, > mike > > -- mike cullerton > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list- admin@lists.php.net > > > Corey Chapman Xnull CEO (Chat with us: http://forum.xnull.com)

« previous php.general (#61169) next »