① 請問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
② html能過JS獲取PHP中的值
1、js獲取php文件的源碼是完全不可能的。
2、如果獲取1.php在瀏覽器中訪問後的頁面內容。用js的ajax獲取到1.php內容,然後分析截取出需要的字元。
③ html如何通過js腳本調用顯示一個php頁面的內容
用javascript形式輸出數據,其實那就是php把js的輸出腳本變為字元串的形式,當js調用會版執行php代碼
例如:輸出的權php文件demo.php
echo 'document.write("'.define('WP_USE_THEMES', false);.'")';
echo 'document.write("'.require('article/wp-blog-header.php');.'")';
echo 'document.write("'.query_posts('showposts=20');.'")';
其它的都是這樣寫就行了
html頁面js調用demo.php
<script type="text/javascript" src="demo.php"></script>
④ php正則怎麼去除js代碼
preg_replace("/<script>wW*</script>/","",$code);
⑤ 根目錄php調用一個子目錄含js腳本的html文件
你路徑不對,你在parts/tourpic/index.html中應該調用的路徑是"./css/xixi.css"和"./js/jquery.js
"
⑥ php文件輸出如何過濾掉html,代碼如下
<b>asasasas</b>這個html標簽是加粗標簽,如果你想在瀏覽器上顯示的是版加粗的asasasas就直接輸出
<?php
echo "<b>asasasas</b>";
?>
如果你想輸權出的<b>asasasas</b>這個字元串的話呢
<?php
echo htmlspecialchars("<b>asasasas</b>");
?>
⑦ php 求正則匹配網頁文件中的css跟js文件
<?php
$content = <<<EOF
<link rel="stylesheet" type="text/css" href="/css/reset.css" />
<link rel="stylesheet" type="text/css" href="/css/style.css" />
<link rel="shortcut icon" href="favicon.ico">
<link rel="shortcut icon" href="favicon.png">
<script type="text/javascript" src="/js/main.js"></script>
<script type="text/javascript" src="/js/jquery.bxslider.js"></script>
EOF;
preg_match_all('/(?:href|src)="(.*?[css|js])"/', $content, $matchs);
var_mp($matchs);
⑧ 求過濾html,js,css標簽的代碼, 網路採集功能。
?是簡單的站內搜索就用MySQL語句就可以了。
⑨ 用 php 或 js 替換 html 代碼內的文字,最好是 php ,但是 js 也行
$str="<body><div>
你好
<p>你好</p>
<span>你好<span>
</div></body>";
$new_str=str_replace("你好","好",$str);
print $new_str;
⑩ php 如何過濾用戶提交的javascript代碼
進行html標簽轉義,例如傳入內容是$content=「<script>alert('sd');</script>」,運行
$content=htmlspecialchars($content);就會將你的內容轉換成
(這回個是轉換後插進資料庫里的答數據)
這個東西放在瀏覽器顯示就是
<script>alert('sd');</script>,但是不會運行裡面的函數。