Ades Design - High Quality Website Templates, Free Website Templates, Tutorials: Photoshop, Dreamweaver, Flash, CSS and PHP


Creating a Secure PHP Login Script by Martin Tsachev
Home » Tutorials » PHP


 

10. Checking persistent login credentials

If the user has chosen to let the script remember him/her then a cookie is saved, which is checked via the following method.

function _checkRemembered($cookie) {

list($username, $cookie) = @unserialize($cookie);
if (!$username or !$cookie) return;

$username = $this->db->quote($username);
$cookie = $this->db->quote($cookie);

$sql = "SELECT * FROM member WHERE " .
"(username = $username) AND (cookie = $cookie)";

$result = $this->db->getRow($sql);

if (is_object($result) ) {
$this->_setSession($result, true);
}

}

This function should not trigger any error messages at all. To make things more secure a cookie value is saved in the cookie not the user password. This way one can request a password for areas which require even higher security.

 

11. Ensuring valid session data

function _checkSession() {

$username = $this->db->quote($_SESSION['username']);
$cookie = $this->db->quote($_SESSION['cookie']);
$session = $this->db->quote(session_id());
$ip = $this->db->quote($_SERVER['REMOTE_ADDR']);

$sql = "SELECT * FROM member WHERE " .
"(username = $username) AND (cookie = $cookie) AND " .
"(session = $session) AND (ip = $ip)";

$result = $this->db->getRow($sql);

if (is_object($result) ) {
$this->_setSession($result, false, false);
} else {
$this->_logout();
}

}

So this is the final part, we check if the cookie saved in the session is right, the session id and the IP address of the visitor. The call to setSession is with a parameter to let it know that this is not the first login to the system and thus not update the IP and session id which would be useless anyway.


[ previous page ]



Web2.0 Bookmarks - Social bookmarking is good, but old skool way of hand-picking sites is better!
That's what we do best, collecting the coolest WEB2.0 sites. click here

 


Advertise | AdesBlog New | Free Templates | Premium Templates | Products | Services | Portfolio | Contact

2002 - 2007 Ades Design. All Rights Reserved. http://www.adesdesign.net

 









Custom Logo Design Services by Logo Design Team for $149 Only
Software Development Company 
Search Engine Optimization by Design
 
Advertise Here