search
HomeBackend DevelopmentPHP TutorialIllegal character filtering_PHP tutorial
Illegal character filtering_PHP tutorialJul 13, 2016 pm 05:09 PM
aspphpSamehostbutfunctioncharacterInfluenceThoughtarticleoffilter

Illegal character filteringThis article mainly talks about php filtering illegal charactersIt does not talk about the function of asp filtering illegal characters, but the idea is the same.

) Filter characters that affect the normal operation of MySQL.

When you need to substitute the content entered by the user (which may include single quotes, double quotes, backslashes, and the null character NUL) into the mysql statement for execution, you should set the magic_quotes_gpc item in APACHE to On.

If this item in APACHE is set to Off, the PHP function addslashes() can also be used to achieve the same purpose, but these two methods cannot be used at the same time, otherwise repeated substitutions will occur and errors will occur.

Sample:

PHP code

if (get_magic_quotes_gpc()) {

$content=$_POST["content"];

} else { 

$content=addslashes($_POST["content"]);



?>

Of course, if the magic_quotes_gpc item in APACHE is On, but sometimes you don’t want to escape the special characters of a certain item, you can use stripslashes() to remove the

2) Filter characters that affect the normal operation of MSSQL.

When you need to substitute the content entered by the user (which may include single quotes) into the mssql statement for execution, you should set the magic_quotes_sybase item in APACHE to On. At this time, the magic_quotes_gpc item will no longer take effect.

If this item in APACHE is set to Off, there is no suitable function in PHP to achieve the same purpose. You can only use the string replacement function to achieve this purpose.

Sample:

PHP code

$content=str_replace("'","''"$_POST["content"]); 

?>

Now PHP on 10.218.17.53 needs to access both mysql and mssql. The settings in APACHE cannot take into account both databases, so only mysql has been set accordingly.

2. A measure to deal with user input containing SQL statements.

The following two SQL writing methods are relatively common, but the security level is different. When the user submits $id='1 and 1=2 union select...', the first one will display something that should not be displayed. data, while the second type is relatively safer.

SQL code
Select * FROM article Where articleid=$id 
Select * FROM article Where articleid='$id'

3. Prevent the content entered by the user from affecting the normal display of the page due to the inclusion of html tags or javascript.

You can use htmlspecialchars() to filter the & "

PHP code
$content = htmlspecialchars($content);

4. When the content to be displayed on the page contains carriage returns and line breaks, you can use nl2br() to achieve the effect of line breaks on the page.
Method 1.

function chkstr($paravalue,$paratype) //Filter illegal characters
{
if($paratype==1)
{
$inputstr=str_replace("'","''",$paravalue);
}
elseif($paratype==2)
{
$inputstr=str_replace("'","",$paravalue);
}
return $inputstr;
}
$user1=chkstr($_GET["user"],1);
$user2=chkstr($_GET["user"],2);
//$user=$_GET["user"];
print "Method 1----------------
";
print "$user1
";
print "Method 2-----------------
";
print "$user2
";
?>
Method 2.


//Usage: qstr($str, get_magic_quotes_gpc())
function qstr($string, $magic_quotes=false, $tag=false)
{
$tag_str = '';
if ($tag) $tag_str = "'";
if (!$magic_quotes) {
If (strnatcmp(PHP_VERSION, '4.3.0') >= 0) {
Return $tag_str.mysql_real_escape_string($string).$tag_str;
}
$string = str_replace("'", "[url=file://\]\'[/url]" , str_replace('\', '\\', str_replace(" Return $tag_str.$string.$tag_str;
}
Return $tag_str.str_replace('\"', '"', $string).$tag_str;
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629753.htmlTechArticleIllegal character filtering This article mainly talks about PHP filtering illegal characters. It does not talk about the function of ASP filtering illegal characters, but the idea is the same. . ) filters characters that affect the normal operation of MySQL. When needed...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何在 Word 中键入箭头如何在 Word 中键入箭头Apr 16, 2023 pm 11:37 PM

如何使用自动更正在 Word 中键入箭头在 Word 中键入箭头的最快方法之一是使用预定义的自动更正快捷方式。如果您键入特定的字符序列,Word 会自动将这些字符转换为箭头符号。您可以使用此方法绘制多种不同的箭头样式。要使用自动更正在 Word 中键入箭头:将光标移动到文档中要显示箭头的位置。键入以下字符组合之一:如果您不希望将您键入的内容更正为箭头符号,请按键盘上的退格键会将

如何在 Microsoft Excel 中应用上标和下标格式选项如何在 Microsoft Excel 中应用上标和下标格式选项Apr 14, 2023 pm 12:07 PM

上标是一个字符或多个字符,可以是字母或数字,您需要将其设置为略高于正常文本行。例如,如果您需要写1st,则字母st需要略高于字符1。同样,下标是一组字符或单个字符,需要设置为略低于正常文本级别。例如,当你写化学式时,你需要把数字放在正常字符行的下方。以下屏幕截图显示了上标和下标格式的一些示例。尽管这似乎是一项艰巨的任务,但实际上将上标和下标格式应用于您的文本非常简单。在本文中,我们将通过一些简单的步骤说明如何轻松地使用上标或下标格式设置文本。希望你喜欢阅读这篇文章。如何在 Excel 中应用上标

如何利用PHP函数进行搜索和过滤数据?如何利用PHP函数进行搜索和过滤数据?Jul 24, 2023 am 08:01 AM

如何利用PHP函数进行搜索和过滤数据?在使用PHP进行开发的过程中,经常需要对数据进行搜索和过滤。PHP提供了丰富的函数和方法来帮助我们实现这些操作。本文将介绍一些常用的PHP函数和技巧,帮助你高效地进行数据的搜索和过滤。字符串搜索PHP中常用的字符串搜索函数是strpos()和strstr()。strpos()用于查找字符串中某个子串的位置,如果存在,则返

如何在 iPhone 和 Mac 上输入扩展字符,例如度数符号?如何在 iPhone 和 Mac 上输入扩展字符,例如度数符号?Apr 22, 2023 pm 02:01 PM

您的物理或数字键盘在表面上提供有限数量的字符选项。但是,有几种方法可以在iPhone、iPad和Mac上访问重音字母、特殊字符等。标准iOS键盘可让您快速访问大写和小写字母、标准数字、标点符号和字符。当然,还有很多其他角色。您可以从带有变音符号的字母到倒置的问号中进行选择。您可能无意中发现了隐藏的特殊字符。如果没有,以下是在iPhone、iPad和Mac上访问它们的方法。如何在iPhone和iPad上访问扩展字符在iPhone或iPad上获取扩展字符非常简单。在“信息”、“

使用java的Character.isDigit()函数判断字符是否为数字使用java的Character.isDigit()函数判断字符是否为数字Jul 27, 2023 am 09:32 AM

使用Java的Character.isDigit()函数判断字符是否为数字字符在计算机内部以ASCII码的形式表示,每个字符都有一个对应的ASCII码。其中,数字字符0到9分别对应的ASCII码值为48到57。要判断一个字符是否为数字,可以使用Java中的Character类提供的isDigit()方法进行判断。isDigit()方法是Character类的

正确在matplotlib中显示中文字符的方法正确在matplotlib中显示中文字符的方法Jan 13, 2024 am 11:03 AM

在matplotlib中正确地显示中文字符,是很多中文用户常常遇到的问题。默认情况下,matplotlib使用的是英文字体,无法正确显示中文字符。为了解决这个问题,我们需要设置正确的中文字体,并将其应用到matplotlib中。下面是一些具体的代码示例,帮助你正确地在matplotlib中显示中文字符。首先,我们需要导入需要的库:importmatplot

PHP和PHPMAILER:如何实现邮件发送的自动过滤功能?PHP和PHPMAILER:如何实现邮件发送的自动过滤功能?Jul 21, 2023 am 09:25 AM

PHP和PHPMAILER:如何实现邮件发送的自动过滤功能?在现代社会中,电子邮件已成为人们交流的重要方式之一。然而,随着电子邮件的流行和广泛使用,垃圾邮件的数量也呈现出爆炸式增长的趋势。垃圾邮件不仅会浪费用户的时间和网络资源,还可能带来病毒和钓鱼行为。因此,在开发邮件发送功能时,加入自动过滤垃圾邮件的功能变得至关重要。本文将介绍如何使用PHP和PHPMai

PHP中的表单验证和过滤方法?PHP中的表单验证和过滤方法?Jun 29, 2023 pm 10:04 PM

PHP作为一种广泛应用于Web开发的脚本语言,其表单验证和过滤是非常重要的一部分。在用户提交表单的过程中,需要对用户输入的数据进行验证和过滤,以确保数据的安全性和有效性。本文将介绍PHP中如何进行表单验证和过滤的方法和技巧。一、表单验证表单验证是指对用户输入的数据进行检查,以确保数据符合特定的规则和要求。常见的表单验证包括对必填项的验证、邮箱格式、手机号码格

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function