php过滤表单提交的html等危险代码,php过滤表单提交
PHP过滤提交表单的html代码里可能有被利用引入外部危险内容的代码。例如,有些时候用户提交表单中含有html内容,但这可能造成显示页面布局混乱,需要过滤掉。
方法一:
复制代码 代码如下:
//get post data
function PostGet($str,$post=0)
{
empty($str)?die('para is null'.$str.'!'):'';
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]:''));
}
}
}
方法二:
复制代码 代码如下:
function uhtml($str)
{
$farr = array(
"/\s+/", //过滤多余空白
//过滤 <script>等可能引入恶意内容或恶意改变显示布局的代码,如果不需要插入flash等,还可以加入<object>的过滤 <br />
"/<(\/?)(script|i?frame|style|html|body|title|link|meta|\?|\%)([^>]*?)>/isU", <br />
"/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU",//过滤javascript的on事件 <br />
); <br />
$tarr = array( <br />
" ", <br />
"<\1\2\3>",//如果要直接清除不安全的标签,这里可以留空 <br />
"\1\2", <br />
); <br />
$str = preg_replace( $farr,$tarr,$str); <br />
return $str; <br />
} <br />
</script>
很实用的方法吧,希望对大家能有所帮助
你没开启魔法函数, 你可以自己使用函数自动转义就可以了.
使用:addslashes 这个函数来转义一下客户端的数据,例如:
$post = addslashes($_POST['value']);
这个时候显示的就是转义后的文子了!
你的HTML代码有错。
。。。你不用

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),