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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to