I have created what I believe to be a secure PHP login form. I won't paste all the code here but basically it runs all post data though the clean function shown below.
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
The following SQL query is used the check if the login data are correct...
$qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'";
If the data is valid, a session is created...
$_SESSION['MID'] = $member['mid'];
For all the secure member only pages, the code checks the see if the session if valid
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
Does the above script look ok and secure? I mean have I left any vulnerabilities anywhere?
Secondly, is setting a session and checking it a good source of authentication? I have noticed several other php scripts such as messages board store the session in the database along with the username and IP address. Why do they do this? I assume the only reason for this is to prevent sessions be hijacked? If so, the IP check would prevent this?