这是我第一个使用 SESSIONS 的登录系统。只是想知道,SQL 注入是否安全?
<?php
$username = $_POST['username'];
$password = $_POST['password'];
if(isset($username, $password)) {
if(get_magic_quotes_gpc()) {
$ousername = stripslashes($username);
$uusername = mysql_real_escape_string(stripslashes($username));
$opassword = stripslashes($_POST['password']);
} else {
$uusername = mysql_real_escape_string($username);
$opassword = $password;
}
$req = mysql_query('select password,id from users where username="'.$uusername.'"');
$dn = mysql_fetch_array($req);
if($dn['password']==$opassword and mysql_num_rows($req)>0)
{
$form = false;
$_SESSION['username'] = $_POST['username'];
$_SESSION['userid'] = $dn['id'];
echo 'Logged in m8';
} else {
$form = true;
$message = 'The username or password is incorrect.';
}
} else {
$form = true;
}
if($form)
{
if(isset($message)) {
echo '<div class="message">'.$message.'</div>';
}
?>
我之前在我的高分脚本上遇到过 SQL 注入,所以我想知道我的简单会话登录脚本是否有,我 40% 有一个。通常是什么导致 SQL 注入?谢谢!