note 69085 added to function.mysql-real-escape-string
| From: | antrecu at yahoo dot com | Date: | Tue, 22 Aug 2006 16:30:52 +0000 |
| Subject: | note 69085 added to function.mysql-real-escape-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116175@lists.php.net to get a copy of this message | ||
Hi everyone, this is a little piece of code, which helps to validates a user into some application,
using mysql_real_escape_string(). hope it can be useful.
function quote_smart($value)
{
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not integer
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}
function validate_SystemUser($user_name, $password){
$password = quote_smart(crypt($password, 'SS'));
$sel_user = "SELECT id FROM user WHERE userName = " . quote_smart($user_name) . "
AND password = " . $password . "";
//DB connection, query execution & returns resulset
$res_user = query($sel_user);
$row_user = mysql_num_rows($res_user);
if($row_user > 0){
while($row_user = mysql_fetch_array($res_user)){
$idUser = $row_user[0];
}
return $idUser;
}else{
//bla bla
}
}
----
Server IP: 66.163.161.117
Probable Submitter: 201.217.101.138
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.mysql-real-escape-string.php
Edit -- https://master.php.net/note/edit/69085
Del: integrated -- https://master.php.net/note/delete/69085/integrated
Del: useless -- https://master.php.net/note/delete/69085/useless
Del: bad code -- https://master.php.net/note/delete/69085/bad+code
Del: spam -- https://master.php.net/note/delete/69085/spam
Del: non-english -- https://master.php.net/note/delete/69085/non-english
Del: in docs -- https://master.php.net/note/delete/69085/in+docs
Del: other reasons-- https://master.php.net/note/delete/69085
Reject -- https://master.php.net/note/reject/69085
Search -- https://master.php.net/manage/user-notes.php