user system using sessions and cookies?

From: Date: Wed, 04 Dec 2002 15:12:07 +0000
Subject: user system using sessions and cookies?
Groups: php.windows 
Request: Send a blank email to php-windows+get-17258@lists.php.net to get a copy of this message
Hi, I am coding a community site and am, (once again) experimenting with a user system. Currently I have a user class that checks the user's username and password with the database and returns them to a login script (with the password md5 encoded). The login script then registers these (password and username) variables using session_register(). My aim is to keep the user logged in indefinitely, until they logout; using the appropriate function. During my experimentation, I have tried session_set_cookie_params() - to no avail. I then reverted to saving the username, password and session id in a cookie and then checking for these, like so: <?PHP session_start(); //get all the extra files needed for every page. include('dbinfo.inc'); include('database.class.php'); include('user.class.php'); //login check if(IsSet($_COOKIE['cookie_username']) && IsSet($_COOKIE['cookie_password'])){ $localuser = new userclass(); $localuser->setup($dbserver,$dbuser,$dbpass,$dbname); $localuser->connect(); $username = $_COOKIE['cookie_username']; $password = $_COOKIE['cookie_password']; $localuser->check_user($username, $password);// check function if($localuser->check){// returned true from the user class if username and md5 hash match with those in the database $s_id = $_COOKIE['cookie_session']; session_id($s_id); session_register('username'); session_register('password'); $login = true; } else{ $login = false; } } else{ $login = false; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>test login</title> </head> <body> <?PHP $username = $_SESSION['username']; $password = $_SESSION['password']; echo"<b>Login</b> = $login <br>"; echo"<b>Username:</b> $username <br>"; echo"<b>Password:</b> $password <br>"; echo"<b>Session ID:</b>"; print(session_id()); ?> The above code gives the following: Login = 1 Username: Password: Session ID:95a607dc349f91b2a08c8533538b8694 Clearly, the login returns true and the session id has been used, but the password and username have not been registered. I have been playing around with this for a while now, and am a little stuck. Any help would be brilliant. Thanks in advance. ******************************************************************** Kieran Hall

« previous php.windows (#17258) next »