Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does php filter dangerous codes such as html submitted by forms?

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article "php how to filter form submission of html and other dangerous code" most people do not understand, so the editor summarized the following content, detailed, clear steps, with a certain reference value, I hope you can get something after reading this article, let's take a look at this "php how to filter form submission of html and other dangerous code" article bar.

PHP filters the html code that submits the form that may be exploited to introduce externally dangerous content. For example, sometimes a user submits a form that contains html content, but this may cause confusion in the layout of the display page and need to be filtered out.

Method 1:

The copy code is as follows:

/ / get post data

Function PostGet ($str,$post=0)

{

Empty ($str)? die ('para is nullroom.roomstr.conversation'):''

If ($post)

{

If (get_magic_quotes_gpc ())

{

Return htmlspecialchars (isset ($_ POST [$str])? $_ POST

[$str]:'')

}

Else

{

Return addslashes (htmlspecialchars (isset ($_ POST [$str])?

$_ POST [$str]:'')

}

}

Else

{

If (get_magic_quotes_gpc ())

{

Return htmlspecialchars (isset ($_ GET [$str])? $_ GET [$str]:')

}

Else

{

Return addslashes (htmlspecialchars (isset ($_ GET [$str])?

$_ GET [$str]:'')

}

}

}

Method 2:

The copy code is as follows:

Function uhtml ($str)

{

$farr = array (

"/\ slots /", / / filter excess whitespace

/ / filtering and other code that may introduce malicious content or change the display layout maliciously. You can also add filtering if you do not need to insert flash, etc.

"/] *?) > / isU"

"/ (] *) on [a-zA-Z] +\ isU = ([^ >] * >) / isU", / / filter the on event of javascript

);

$tarr = array (

"

"<\ 1\ 2\ 3 >", / / if you want to clear unsafe tags directly, you can leave it blank here.

"\ 1\ 2"

);

$str = preg_replace ($farr,$tarr,$str)

Return $str

}

The above is about "php how to filter form submitted html and other dangerous code" of this article, I believe we all have a certain understanding, I hope the content shared by the editor will be helpful to you, if you want to know more related knowledge content, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report