导航:首页 > 编程语言 > php过滤script

php过滤script

发布时间:2022-08-06 20:30:21

㈠ 用php过滤html部分标签

$str=preg_replace("/\s+/", " ", $str); //过滤多余回车
$str=preg_replace("/<[ ]+/si","<",$str); //过滤<__("<"号后面带空格)

$str=preg_replace("/<\!--.*?-->/si","",$str); //注释
$str=preg_replace("/<(\!.*?)>/si","",$str); //过滤DOCTYPE
$str=preg_replace("/<(\/?html.*?)>/si","",$str); //过滤html标签
$str=preg_replace("/<(\/?head.*?)>/si","",$str); //过滤head标签
$str=preg_replace("/<(\/?meta.*?)>/si","",$str); //过滤meta标签
$str=preg_replace("/<(\/?body.*?)>/si","",$str); //过滤body标签
$str=preg_replace("/<(\/?link.*?)>/si","",$str); //过滤link标签
$str=preg_replace("/<(\/?form.*?)>/si","",$str); //过滤form标签
$str=preg_replace("/cookie/si","COOKIE",$str); //过滤COOKIE标签

$str=preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si","",$str); //过滤applet标签
$str=preg_replace("/<(\/?applet.*?)>/si","",$str); //过滤applet标签

$str=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$str); //过滤style标签
$str=preg_replace("/<(\/?style.*?)>/si","",$str); //过滤style标签

$str=preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si","",$str); //过滤title标签
$str=preg_replace("/<(\/?title.*?)>/si","",$str); //过滤title标签

$str=preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si","",$str); //过滤object标签
$str=preg_replace("/<(\/?objec.*?)>/si","",$str); //过滤object标签

$str=preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si","",$str); //过滤noframes标签
$str=preg_replace("/<(\/?noframes.*?)>/si","",$str); //过滤noframes标签

$str=preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si","",$str); //过滤frame标签
$str=preg_replace("/<(\/?i?frame.*?)>/si","",$str); //过滤frame标签

$str=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$str); //过滤script标签
$str=preg_replace("/<(\/?script.*?)>/si","",$str); //过滤script标签
$str=preg_replace("/javascript/si","Javascript",$str); //过滤script标签
$str=preg_replace("/vbscript/si","Vbscript",$str); //过滤script标签
$str=preg_replace("/on([a-z]+)\s*=/si","On\\1=",$str); //过滤script标签
$str=preg_replace("/&#/si","&#",$str); //过滤script标签,如javAsCript:alert(

清除空格,换行

function DeleteHtml($str)
{
$str = trim($str);
$str = strip_tags($str,"");
$str = ereg_replace("\t","",$str);
$str = ereg_replace("\r\n","",$str);
$str = ereg_replace("\r","",$str);
$str = ereg_replace("\n","",$str);
$str = ereg_replace(" "," ",$str);
return trim($str);
}

过滤HTML属性

1,过滤所有html标签的正则表达式:

复制代码 代码如下:

</?[^>]+>

//过滤所有html标签的属性的正则表达式:

$html = preg_replace("/<([a-zA-Z]+)[^>]*>/","<\\1>",$html);

3,过滤部分html标签的正则表达式的排除式(比如排除<p>,即不过滤<p>):

复制代码 代码如下:

</?[^pP/>]+>

4,过滤部分html标签的正则表达式的枚举式(比如需要过滤<a><p><b>等):

复制代码 代码如下:

</?[aApPbB][^>]*>

5,过滤部分html标签的属性的正则表达式的排除式(比如排除alt属性,即不过滤alt属性):

复制代码 代码如下:

\s(?!alt)[a-zA-Z]+=[^\s]*

6,过滤部分html标签的属性的正则表达式的枚举式(比如alt属性):

复制代码 代码如下:

(\s)alt=[^\s]*

㈡ php 正则 怎么写

|<SCRIPT \b(?!.*\bsrc\s*=.*?\>)[^>]+>([^<]+)</SCRIPT>|is

㈢ php怎么过滤

使用单独一个模块,这个模块负责所有的安全处理。

这个模块被包含在所有公开的 PHP 脚本的最前端(或者非常靠前的部分)。

参考下面的脚本security.inc

<?php
switch($_POST['form'])
{
case'login':
$allowed=array();
$allowed[]='form';
$allowed[]='username';
$allowed[]='password';
$sent=array_keys($_POST);
if($allowed==$sent)
{
include'/inc/logic/process.inc';
}
break;
}
?>

㈣ php 过滤掉html标签及标签内的所有内容

方法一:使用strip_tags()函数
strip_tags() 函数剥去字符串中的 HTML、XML 以及PHP的标签。
使用案例:
$string = "<p>这里是潘旭博客</p>"
$newStr = strip_tags($string);
echo $newStr;

方法二:使用str_replace()函数
str_replace() 函数以其他字符替换字符串中的一些字符(区分大小写)
使用案例:
$string = "<p>这里是潘旭博客</p>";
$newStr = str_replace(array("<p>","</p>"),array("",""));
echo $newStr;

另外还有一种是通过正则的方法,请参考:https://panxu.net/article/8385.html

㈤ php怎么过滤script代码和其他不安全的一些脚本代码呢 本人刚学php,不懂哎,请各位朋友指点一下。

if(preg_match("/<script>/",$_POST['mima'])){
echo"输入有误";
}

㈥ PHP网站如何过滤页面提交的<SCRIPT脚本

你是想过滤掉还是想按照字面输出?
算了,都告诉你吧
1.过滤掉 strip_tags($content); 这个是所有标签,都被去掉了
2.按照原样显示
htmlspecialchars($content);
感觉这个还是不错的,推荐用这个,呵呵

㈦ 我做了一个留言板现在想用PHP过滤代码,应该怎么做呀详细思路,谢谢!

function filterhtml($str)
{
$str=stripslashes($str);

$str=preg_replace("/\s+/", ' ', $str); //过滤多余回车
$str=preg_replace("/<[ ]+/si",'<',$str); //过滤<__("<"号后面带空格)

$str=preg_replace("/<\!--.*?-->/si",'',$str); //注释
$str=preg_replace("/<(\!.*?)>/si",'',$str); //过滤DOCTYPE
$str=preg_replace("/<(\/?html.*?)>/si",'',$str); //过滤html标签
$str=preg_replace("/<(\/?head.*?)>/si",'',$str); //过滤head标签
$str=preg_replace("/<(\/?meta.*?)>/si",'',$str); //过滤meta标签
$str=preg_replace("/<(\/?body.*?)>/si",'',$str); //过滤body标签
$str=preg_replace("/<(\/?link.*?)>/si",'',$str); //过滤link标签
$str=preg_replace("/<(\/?form.*?)>/si",'',$str); //过滤form标签
$str=preg_replace("/cookie/si","COOKIE",$str); //过滤COOKIE标签

$str=preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si",'',$str); //过滤applet标签
$str=preg_replace("/<(\/?applet.*?)>/si",'',$str); //过滤applet标签

$str=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si",'',$str); //过滤style标签
$str=preg_replace("/<(\/?style.*?)>/si",'',$str); //过滤style标签

$str=preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si",'',$str); //过滤title标签
$str=preg_replace("/<(\/?title.*?)>/si",'',$str); //过滤title标签

$str=preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si",'',$str); //过滤object标签
$str=preg_replace("/<(\/?objec.*?)>/si",'',$str); //过滤object标签

$str=preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si",'',$str); //过滤noframes标签
$str=preg_replace("/<(\/?noframes.*?)>/si",'',$str); //过滤noframes标签

$str=preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si",'',$str); //过滤frame标签
$str=preg_replace("/<(\/?i?frame.*?)>/si",'',$str); //过滤frame标签

$str=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si",'',$str); //过滤script标签
$str=preg_replace("/<(\/?script.*?)>/si",'',$str); //过滤script标签
$str=preg_replace("/javascript/si","JAVASCRIPT",$str); //过滤script标签
$str=preg_replace("/vbscript/si","VBSCRIPT",$str); //过滤script标签
$str=preg_replace("/on([a-z]+)\s*=/si","ON\\1=",$str); //过滤script标签
$str=preg_replace("/&#/si","&#",$str); //过滤script标签,如javAsCript:alert('aabb)

$str=addslashes($str);
return($str);
}

㈧ PHP 过滤HTML中除了img标签外其它所有标签,同时保留标签内容,但<script>标签内的内容都清除。

提供实例:
<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// 允许 <p> 和 <a>
echo strip_tags($text, '<p><a>');
?>
以上例程会输出:
Test paragraph. Other text
<p>Test paragraph.</p> <a href="#fragment">Other text</a>

具体做法:
<?php
echo strip_tags($text, 'img');
?>

㈨ php如何处理html标签

需要用到一个函数实现,htmlentities,就是将字符串转换成html实体,用法你可以查一下php手册,同时它还有个反函数,htmlspecialchars_decode

㈩ php中,在提交表单时,script代码是通过什么方式对网站进行破坏如何防止破坏

其实JS代码不会在提交的时候对网站进行破坏,因为它不会运行。而是会在输出的时候进行破坏,比如一篇没有过滤的文章里 输入<script>alert(0)</script>,在文章页面调用的时候会自动弹出。更深层次的,会对网站的COOKIE进行破坏和重构,导致个人数据泄露,当然,这个可能性我感觉不大。只要对提交的表单,进行script的过滤就可以,简单、粗暴,不让这个<script>出现,其他的代码就是文字了。

阅读全文

与php过滤script相关的资料

热点内容
证券技术分析pdf 浏览:769
linux命令连接oracle 浏览:200
垫江停车收费桩怎么上App 浏览:133
好兴动app还款怎么登录不上去了 浏览:665
郑州云服务器托管 浏览:722
服务器地址跟踪 浏览:980
免费google云服务器 浏览:516
摘译和编译的英文 浏览:359
热泵压缩机选型 浏览:121
op手机微信加密如何解除 浏览:386
如何在王牌战争找到高爆率服务器 浏览:13
江浙小学语文辅导课用什么APP 浏览:99
新梦幻大陆服务器地址 浏览:241
网吧服务器怎么更换壁纸 浏览:530
linux命令方法 浏览:332
linux下载freetype 浏览:123
程序员入驻平台 浏览:327
程序员大战外挂 浏览:745
html实例教程pdf 浏览:157
linux命令开放所有权限 浏览:575