这是我在PHP中进行的简单注册。 我只是想知道如何让它真正安全,因为我是PHP的新手,所以示例也会有所帮助。总而言之,任何资源或指导都会很棒。
<?php
$email = $_POST["email"];
$password = $_POST["password"];
$fname = $_POST["first_name"];
$lname = $_POST["last_name"];
$db = "mydatabase";
$connect = mysql_connect("localhost","root","");
if(!$connect){
die('Could not connect.');
}
$query = "INSERT INTO users (id, email, password, first_name, last_name) VALUES (DEFAULT, '".$email."', '".$password."', '".$fname."', '".$lname."')";
mysql_select_db($db, $connect);
if(!mysql_query($query)){
echo 'Failed: '.mysql_error();
}
else{
echo 'You have registered.';
}
mysql_close($connect);
?>
这是注册输入表单
<html>
<head>
</html>
<body>
<form action="new_user_db.php" method="POST">
<input type="text" name="first_name" placeholder="First Name" required><br>
<input type="text" name="last_name" placeholder="Last Name" required><br>
<input type="email" name="email" placeholder="E-mail" required><br>
<input type="password" name="password" placeholder="Password" required><br>
<input type="submit" value="Register">
</form>
</body>
</html>
感谢您的所有反馈!
答案 0 :(得分:2)
安全问题:
答案 1 :(得分:1)
使用准备好的声明
$db = mysqli_connect($dbserver, $dbuser, $dbpass,$dbname);
$sql = "insert into mytable (mycol1, mycol2) values (?,?)";
$statement = $db->prepare($sql);
$statement -> bindparam("ss",$myval1, $myval2)'
mysqli_stmt_execute(#statement);