我的php代码对用户名的所有特殊字符都适用吗?

我的php代码对用户名的所有特殊字符都适用吗?,php,login,Php,Login,我在注册页面上输入用户可能使用的所有特殊字符时遇到问题,如空格、@、“.”等。我使用了以下字符:- <?php if(isset($_POST["user_login"]) && isset($_POST["password_login"])) { $user_login = preg_replace('#[^A-Za-z0-9@._\(\)\']#i', '', $_POST["user_login"]); $password_login = preg_replace(

我在注册页面上输入用户可能使用的所有特殊字符时遇到问题,如空格、@、“.”等。我使用了以下字符:-

<?php

if(isset($_POST["user_login"]) && isset($_POST["password_login"])) {
$user_login = preg_replace('#[^A-Za-z0-9@._\(\)\']#i', '', $_POST["user_login"]);
$password_login = preg_replace('#[^A-Za-z0-9!@._]#i', '', $_POST["password_login"]);
$md5password_login = md5($password_login);
$sql = mysql_query("SELECT id FROM users WHERE username='$user_login' AND password='$md5password_login' LIMIT 1");
//check for their existance
$userCount = mysql_num_rows($sql); //count the number of rows returned
if ($userCount == 1) {
while($row = mysql_fetch_array($sql)) {

$id = $row["id"];
}
$_SESSION["id"] = $id;
$_SESSION["user_login"] = $user_login;
$_SESSION["password_login"] = $password_login;
exit("<meta http-equiv=\"refresh\" content=\"0\">");
} else {
echo "Your Username or Password is Incorrect. please try again.";
exit();
}
}
?>

从用户密码中删除字符是一个非常糟糕的主意。另外,
mysql\u query
也不推荐使用。它正在从语言中删除,您不应该使用它。是的,我知道它将被弃用。我以后会改的。如果我听过的话,这是一些著名的临终遗言。这应该写在程序员的T恤上。“以后”是站不住脚的,现在就改变它,因为你不太喜欢在上面构建你正在使用的并且需要修改你的用户密码。
<form method="post" action="index.php" id="login_form" name="login_form">
          <table border="" style="border:none">
            <tr>
              <td ><input type="text" tabindex="1"  id="email" placeholder="Username or Phone" name="user_login" class="inputtext radius1" value="" autofocus="autofocus"/></td>
              <td ><input type="password" tabindex="2" id="pass" placeholder="Password" name="password_login" class="inputtext radius1"/></td>
              <td ><input type="submit" class="hpbutton" name="button" value="Log In" /></td>
            </tr>
          </table>
        </form>