我的登錄表單有問題SQL注入正在處理它,所以如何阻止它。如何從sql注入保存我的登錄表單
我使用mysql_real_escape_string
,但什麼都沒有改變
if(isset($_POST['submit-login'])) {
$user = $_POST['username'];
$pass = $_POST['password'];
$username = mysql_real_escape_string($user);
$password = mysql_real_escape_string($pass);
$usertool = new Usertool();
if($usertool->login($username, $password)){
//successful login, redirect them to a page
header("Location: index.php");
}else{
$error = "Incorrect username or password. Please try again.";
}
}
這裏是usertool
class usertool {
public function login($username, $password) {
$hashedPassword = md5($password);
$result = mysql_query("SELECT * FROM tbl_user WHERE uname = '$username' OR eemail = '$username' AND password = '$hashedPassword'");
if (mysql_num_rows($result) == 1) {
$_SESSION["user"] = serialize(new User(mysql_fetch_assoc($result)));
$_SESSION["login_time"] = time();
$_SESSION["logged_in"] = 1;
return true;
} else {
return false;
}
}
按照這個http://stackoverflow.com/questions/60174/how-to-prevent-sql-injection-in-php?rq=1 – Rahul11
@ØHankyPankyØ這是不正確的。無論是奉獻還是避免mysql ext都可以影響sql注入漏洞 –
@YourCommonSense採取的建議和刪除的註釋 –