数据库
首页 > 数据库> > 如何在PHP MYSQL中验证字符串?

如何在PHP MYSQL中验证字符串?

作者:互联网

我正在使用带有准备声明的PDO.

我正在使用Javascript从html textarea加密文本,在PHP中解密,添加了一些文本,然后在将数据写入数据库之前重新加密了数据.

我正在使用PHP从db解密数据并将其放在HTML5页面中.

通常,内容是HTML编码文本的结果.

addlashes,htmlentities和preg_replace …我可以用对我来说最好的方式来验证/过滤数据吗?

验证和过滤数据之间有什么区别?

我没有安全经验.请帮助我找到适用于我的应用程序的最佳方法.

提前致谢

解决方法:

我认为这对我来说是一个很好的解决方案.

你怎么看待这件事?

 function clearPasswrod($value){


     $value = trim($value); //remove empty spaces
     $value = strip_tags(); //remove html tags
     $value = htmlentities($value, ENT_QUOTES,'UTF-8'); //for major security transform some other chars into html corrispective...

      return $value;
 }
 function clearText($value){

     $value = trim($value); //remove empty spaces
     $value = strip_tags(); //remove html tags
     $value = filter_var($value, FILTER_SANITIZE_MAGIC_QUOTES); //addslashes();
     $value = filter_var($value, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); //remove /t/n/g/s
     $value = filter_var($value, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); //remove é à ò ì ` ecc...
     $value = htmlentities($value, ENT_QUOTES,'UTF-8'); //for major security transform some other chars into html corrispective...

     return $value;
 }
 function clearEmail($value){


     $value = trim($value); //remove empty spaces
     $value = strip_tags(); //remove html tags
     $value = filter_var($value, FILTER_SANITIZE_EMAIL); //e-mail filter;
     if($value = filter_var($value, FILTER_VALIDATE_EMAIL))
   {
     $value = htmlentities($value, ENT_QUOTES,'UTF-8');//for major security transform some other chars into html corrispective...
   }else{$value = "BAD";}  
     return $value;
 }

标签:addslashes,validation,html-entities,mysql,php
来源: https://codeday.me/bug/20191122/2057184.html