Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php中的登录表单问题,删除特殊字符但接受希腊字母_Php_Sql Injection_Form Submit - Fatal编程技术网

php中的登录表单问题,删除特殊字符但接受希腊字母

php中的登录表单问题,删除特殊字符但接受希腊字母,php,sql-injection,form-submit,Php,Sql Injection,Form Submit,我正在为我的网站制作一个注册/登录表单,但我遇到了一个问题。。。 尝试使名称和姓氏表单中的输入字符串尽可能干净。我尝试了许多预制函数来搜索字符串,不允许用户使用特殊字符,如@#$%^&*({})等,但当用户使用希腊字符(没有特殊字符)书写姓名或姓氏时,该函数将读取特殊字符。下面是代码: $required_fields = array('name', 'surname', 'email', 'password', 'confirm_password'); $wrong_chars = "0123

我正在为我的网站制作一个注册/登录表单,但我遇到了一个问题。。。 尝试使名称和姓氏表单中的输入字符串尽可能干净。我尝试了许多预制函数来搜索字符串,不允许用户使用特殊字符,如@#$%^&*({})等,但当用户使用希腊字符(没有特殊字符)书写姓名或姓氏时,该函数将读取特殊字符。下面是代码:

$required_fields = array('name', 'surname', 'email', 'password', 'confirm_password');
$wrong_chars = "0123456789!@#$%^&*()+=-[]';,./{}|:<>?~";

foreach($required_fields as $field) {
        if($_POST[$field] == '') {
          $errors[] = "All Fields are required.";
          break;
        }
    }   

     if(empty($errors)) {
         if(strpbrk($name,$wrong_chars) !== false) {
           $errors[] = "You can't use special characters on field: Name.";  
         }
         else if(strpbrk($surname,$wrong_chars) !== false){
             $errors[] = "You can't use special characters on field: Surame.";
         }
     }
$required_fields=array('name'、'姓氏'、'email'、'password'、'confirm_password');
$Error_chars=“0123456789!@#$%^&*()+=-[]';,./{}|:?~";
foreach($必填字段作为$字段){
如果($_POST[$field]=''){
$errors[]=“所有字段都是必填项。”;
打破
}
}   
if(空($errors)){
if(strpbrk($name,$error_chars)!==false){
$errors[]=“您不能在字段名称上使用特殊字符。”;
}
else if(strpbrk($姓氏,$error_chars)!==false){
$errors[]=“您不能在字段:Surame上使用特殊字符。”;
}
}

在此提供的任何帮助以及对更好算法的任何建议都将不胜感激。请提前感谢。

您不能使用此方法,因为许多成员的名字都带有特殊字符,但如果您想这样做,可以使用如下函数:

$user = array();
$required_fields = array('name', 'surname', 'email', 'password', 'confirm_password');

foreach($required_fields as $field) {
    if(!array_key_exists($field,$_POST) || empty($_POST[$field])) {
        $errors[] = "$field field are required.";
    } else {
        $user[$field] = htmlentities($_POST[$field],ENT_QUOTES,'UTF-8');
    }
}   
$user = (object)$user;
if(empty($errors)) {
    if(!ctype_alnum($user->name)) {
        $errors[] = "You can't use special characters on field: Name.";  
    } elseif(!ctype_alnum($user->surname)) {
        $errors[] = "You can't use special characters on field: Surame.";
    }
}
var_dump($errors);

“试图避免sql注入”-然后使用预先准备好的语句,并将脚本转换为接受UTF-8(因此它接受希腊字母)。查看和。不起作用…我仍然输入hello!@#SSFASD这样的名称,并且它被接受…你能告诉我打印的内容是什么吗:echo(!ctype_alnum(htmlentities('hello!@#SSFASD',entu QUOTES,'UTF-8'))?0:1;