这个登录函数是否安全,我将url数据直接放入函数中,但这样做是否不安全?它是否容易受到注入攻击?尽管我知道它没有SQL注入漏洞,但它是否容易受到其他漏洞的攻击?
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$login = check_login($_POST['emailusername'], $_POST['password']);
if ($login) {
// Registration Success
header("location: /");
} else {
// Registration Failed
echo 'Username / password wrong';
}
}
功能:
// CHECK LOGIN SCRIPT
function check_login($emailusername, $password)
{
$host = 'localhost';
$port = 3306; // This is the default port for MySQL
$database = 'example';
$username1 = 'root';
$password1 = 'root';
$dsn = "mysql:host=$host;port=$port;dbname=$database";
$db = new PDO($dsn, $username1, $password1);
$password = md5($password);
$statement = $db->prepare('SELECT uid FROM users WHERE (email = ? or username = ?) and password = ?');
$statement->execute(array($emailusername, $emailusername, $password));
if ($result = $statement->fetchObject()) {
$_SESSION['login'] = true;
$_SESSION['uid'] = $result->uid;
return TRUE;
}else{
return FALSE;
} }
check_login
函数。你能把它粘贴过来吗? - Nemoden