Re: Trying to understand sessions and using them to authenticate...
| From: | Borokov Smith | Date: | Fri, 24 Aug 2007 17:30:00 +0000 |
| Subject: | Re: Trying to understand sessions and using them to authenticate... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-261246@lists.php.net to get a copy of this message | ||
Daniel Brown schreef:
<? session_start(); if(!$_SESSION['user']) {And all it needed was mysql_real_escape_string() in there.if($_POST['user'] && $_POST['pass']) { // Keep in mind, PASSWORDhas meaning in MySQL// Do your string sanitizing here // (e.g. - $user = mysql_real_escape_string($_POST['user']);) $sql = "SELECT * FROM users WHERE user='".$user."' ANDpass='".$pass."' LIMIT 0,1;";$result = mysql_query($sql) or die("Wrong data supplied ordatabase error");while($row = mysql_fetch_array($result)) { $_SESSION['user'] = $row['user']; // Do whatever else you need to do here.... } } else { // Show your login form here. }} else {// The user is authenticated and logged in already.} ?>Keep in mind that, as always, this hasn't been bug-checked,re-read, or otherwise validated. A warrant about your example not being validated, will most likely not stop the OP from using this code as is, thereby subjecting himself to SQL injection.