...

Creating a login system- use sessions or cookies?

WA
08-10-2002, 09:34 AM
I'm reading up on sessions and cookies in PHP, and am a little confused on the usage between the two.

For example, lets say I want to create a typical username/password login form to allow visitors to login and browse the rest of the site, with the option to "remember login info permanantly." For the later part, what is the most common way of implementing such a feature? Is it to

1) Store the name/password set on the user's computer using permanant cookies during their initial log-in, then upon their return, retrieve and set this info as session variables each time

2) Or is there a way for PHP sessions alone to handle the entire process without resorting to cookies? I read how one could session_encode() a session, then store the info on the server, though how would this info then be matched up with each member that returns to the site?

From a novice point of view, it would seem implementing a "remember user login permanantly" feature can only be acomplished using 1).

Thanks for any insight.

Ökii
08-10-2002, 10:30 AM
You would obviously need some way of identifying the clients PC
when they returned in order for a log-back-in-automatically facility to work. I'm sure you are aware that any variable sniffing script is prone to glitch (eg sniff the IP would glitch on dynamic IP machines), thus pointing toward your having to set your very own variable upon their PC that you can read when they return.

Result === cookies.

firepages
08-10-2002, 11:13 AM
Hi, you can try using session_set_cookie_params() , which allws you to set the expiry of the cookie that sessions automatically set (assuming session.use_cookies is enabled in the php.ini)

note you have to use session_set_cookie_params() before you session_start()!

eg:

<?
$expireTime = 3600*24*100; // 100 days
session_set_cookie_params($expireTime);
session_start();
session_register("this_session");
$this_session="hello";
?>

however I am unsure if the sesion garbage collection routine will cause problems with this (I assume it will ?) unless you set handle the garbage collection yourself - never tried , but will have a play.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum