❶ 請問PHP怎麼過濾GET或者POST的參數防止js注入,或者一些html注入請請提供代碼參考謝謝!
string mysql_real_escape_string ( string unescaped_string [, resource link_identifier])
本函數將來 unescaped_string 中的特殊字元自轉義,並計及連接的當前字元集,因此可以安全用於 mysql_query()。
注: mysql_real_escape_string() 並不轉義 % 和 _。
例子 1. mysql_real_escape_string() 例子
<?php
$item = "Zak's and Derick's Laptop";
$escaped_item = mysql_real_escape_string($item);
printf ("Escaped string: %s\n", $escaped_item);
?>
以上例子將產生如下輸出:
Escaped string: Zak\'s and Derick\'s Laptop
❷ php 如何過濾用戶提交的javascript代碼
進行html標簽轉義,例如傳入內容是$content=「<script>alert('sd');</script>」,運行
$content=htmlspecialchars($content);就會將你的內容轉換成
(這回個是轉換後插進資料庫里的答數據)
這個東西放在瀏覽器顯示就是
<script>alert('sd');</script>,但是不會運行裡面的函數。
❸ 幾個有用的php字元串過濾,轉換函數
explode — 使用一個字元串分割另一個字元串
array explode ( string $delimiter , string $string [, int $limit ] )
此函數返回由字元串組成的數組,每個專元素都是 string 的一個子屬串,它們被字元串 delimiter 作為邊界點分割出來。
<?php// 示例 1$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";$pieces = explode(" ", $pizza);echo $pieces[0]; // piece1echo $pieces[1]; // piece2 // 示例 2$data = "foo:*:1023:1000::/home/foo:/bin/sh";list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);echo $user; // fooecho $pass; // * ?>
❹ js 如何過濾div里內的指定字元
String.replace(正則表達式,"")
replace是string類型內置的替換方法,第一個參數可以是正則表達式,第二個參數是版想要權替換成的文本,正則中可以使用/g來表示替換所有匹配的文本,不使用則代表只替換匹配到的第一個字元對象,將第二個參數設為空字元串便可達到過濾的效果。
具體正則需要你自己去了解關於正則的知識了,祝你好運。
❺ JS中的表單,怎樣用PHP過濾用戶名和密碼
js中表單想用戶體驗好點,使用滑鼠移開表單 ajax提交用戶名後台php正常驗證在返回正確失敗
❻ PHP字元串過濾
可以用正則實現抄。給定字元串的規律是3冒號1分號中,前兩個冒號之前是數字,需要的是第三個冒號與分號之前的部分。可如下處理:
<?php
$string = "6939376:28407:包裝方式:包裝;5392114:75367881:重量(g):500;20000:7343430:品牌:蒙園;";
preg_match_all("/[^:\d]+:[^;]+;/", $string, $out);
$rst = implode("", $out[0]);
echo $rst;
?>
$rst為"包裝方式:包裝;重量(g):500;品牌:蒙園;"。已經測試是可行的(php5),如有問題歡迎繼續交流
❼ PHP如何過濾單引號
<?php
functiongetpost($arr){
if(get_magic_quotes_gpc()){
$arr=is_array($arr)?array_map('stripslashes',$arr):stripslashes($arr);
}
if(is_array($arr)){
foreach($arras$key=>$val){
$arr[$key]=htmlspecialchars($val,ENT_QUOTES);//html實體轉換
$arr[$key]=mysql_real_escape_string($arr[$key]);//防注入替換
}
}else{
$arr=htmlspecialchars($arr,ENT_QUOTES);//html實體轉換
$arr=mysql_real_escape_string($arr);//防注入替換
}
return$arr;
}
?>
//該函數是我自己寫的一個轉換函數,主要用於防sql注入和跨站攻擊,參數可以是數組,或字元串
//$post_array=getpost($_POST);//即可完成對敏感字元的處理
❽ PHP字元串中特殊符號的過濾方法介紹
本篇文章主要是對PHP字元串中特殊符號的過濾方法進行了詳細的介紹,需要的朋友可以過來參考下,希望對大家有所幫助
有時候我們會遇到過濾字元串中特殊字元的問題,本文提供了一個處理特殊字元串的方法,可能有遺漏,如果讀者發現了可以
代碼如下:
function
strFilter($str){
$str
=
str_replace('`',
'',
$str);
$str
=
str_replace('·',
'',
$str);
$str
=
str_replace('~',
'',
$str);
$str
=
str_replace('!',
'',
$str);
$str
=
str_replace('!',
'',
$str);
$str
=
str_replace('@',
'',
$str);
$str
=
str_replace('#',
'',
$str);
$str
=
str_replace('$',
'',
$str);
$str
=
str_replace('¥',
'',
$str);
$str
=
str_replace('%',
'',
$str);
$str
=
str_replace('^',
'',
$str);
$str
=
str_replace('……',
'',
$str);
$str
=
str_replace('&',
'',
$str);
$str
=
str_replace('*',
'',
$str);
$str
=
str_replace('(',
'',
$str);
$str
=
str_replace(')',
'',
$str);
$str
=
str_replace('(',
'',
$str);
$str
=
str_replace(')',
'',
$str);
$str
=
str_replace('-',
'',
$str);
$str
=
str_replace('_',
'',
$str);
$str
=
str_replace('——',
'',
$str);
$str
=
str_replace('+',
'',
$str);
$str
=
str_replace('=',
'',
$str);
$str
=
str_replace('|',
'',
$str);
$str
=
str_replace('',
'',
$str);
$str
=
str_replace('[',
'',
$str);
$str
=
str_replace(']',
'',
$str);
$str
=
str_replace('【',
'',
$str);
$str
=
str_replace('】',
'',
$str);
$str
=
str_replace('{',
'',
$str);
$str
=
str_replace('}',
'',
$str);
$str
=
str_replace(';',
'',
$str);
$str
=
str_replace(';',
'',
$str);
$str
=
str_replace(':',
'',
$str);
$str
=
str_replace(':',
'',
$str);
$str
=
str_replace(''',
'',
$str);
$str
=
str_replace('"',
'',
$str);
$str
=
str_replace('“',
'',
$str);
$str
=
str_replace('”',
'',
$str);
$str
=
str_replace(',',
'',
$str);
$str
=
str_replace(',',
'',
$str);
$str
=
str_replace('<',
'',
$str);
$str
=
str_replace('>',
'',
$str);
$str
=
str_replace('《',
'',
$str);
$str
=
str_replace('》',
'',
$str);
$str
=
str_replace('.',
'',
$str);
$str
=
str_replace('。',
'',
$str);
$str
=
str_replace('/',
'',
$str);
$str
=
str_replace('、',
'',
$str);
$str
=
str_replace('?',
'',
$str);
$str
=
str_replace('?',
'',
$str);
return
trim($str);
}
❾ php 過濾JS問題
正則表達式加反轉義引號
code:
<?php
$string=stripcslashes("document.write('<a href=\'http://www.700la.com\' title=\'123\' target=\'_blank\'>123</a>');");
echo $string."\n";
echo preg_replace("/document.write\((?:\'|\")(.*)(?:\'|\")\);/i","$1", $string);
?>
output:
---------- php ----------
document.write('<a href='http://www.700la.com' title='123' target='_blank'>123</a>');
<a href='http://www.700la.com' title='123' target='_blank'>123</a>
輸出完成 (耗時: 0 秒) - 正常終止
❿ php正則怎麼去除js代碼
preg_replace("/<script>wW*</script>/","",$code);