給wordpress 增加幹擾碼防採集_PHP教程

來源:互聯網
上載者:User
開啟 wp-includes下的post-template.php

先將代碼加到 post-template.php 第一行

以下為引用的內容:
function RndString($body)
{
//最大間隔距離(如果在檢測不到p標記的情況下,加入混淆字串的最大間隔距離)
$maxpos = 1024;
//font 的字型顏色
$fontColor = “#FFFFFF”;
//div span p 標記的隨機樣式
$st1 = chr(mt_rand(ord(”A”),ord(”Z”))).chr(mt_rand(ord(”a”),ord(”z”))).chr(mt_rand(ord(”a”),ord(”z”))).mt_rand(100,999);
$st2 = chr(mt_rand(ord(”A”),ord(”Z”))).chr(mt_rand(ord(”a”),ord(”z”))).chr(mt_rand(ord(”a”),ord(”z”))).mt_rand(100,999);
$st3 = chr(mt_rand(ord(”A”),ord(”Z”))).chr(mt_rand(ord(”a”),ord(”z”))).chr(mt_rand(ord(”a”),ord(”z”))).mt_rand(100,999);
$st4 = chr(mt_rand(ord(”A”),ord(”Z”))).chr(mt_rand(ord(”a”),ord(”z”))).chr(mt_rand(ord(”a”),ord(”z”))).mt_rand(100,999);
$rndstyle[1]["value"] = “.{$st1} { display:none; }”;
$rndstyle[1]["name"] = $st1;
$rndstyle[2]["value"] = “.{$st2} { display:none; }”;
$rndstyle[2]["name"] = $st2;
$rndstyle[3]["value"] = “.{$st3} { display:none; }”;
$rndstyle[3]["name"] = $st3;
$rndstyle[4]["value"] = “.{$st4} { display:none; }”;
$rndstyle[4]["name"] = $st4;
$mdd = mt_rand(1,4);
//以後內容如果你不懂其含義,請不要改動
//—————————————————
$rndstyleValue = $rndstyle[$mdd]["value"];
$rndstyleName = $rndstyle[$mdd]["name"];
$reString = “ “;
//附機標記
$rndem[1] = “font”;
$rndem[2] = “div”;
$rndem[3] = “span”;
$rndem[4] = “p”;
//讀取字串資料
$fp = fopen(dirname(__FILE__).”/RndString.php”,”r”);
$start = 0;
$totalitem = 0;
while(!feof($fp)){
$v = trim(fgets($fp,128));
if($start==1){
if(ereg(”#end#”,$v)) break;
if($v!=”"{ $totalitem++; $rndstring[$totalitem] = ereg_replace(”#,”,”",$v); }
}
if(ereg(”#start#”,$v)){ $start = 1; }
}
fclose($fp);
//處理要防採集的欄位
$bodylen = strlen($body) - 1;
$prepos = 0;
for($i=0;$i<=$bodylen;$i++){
if($i+2 >= $bodylen || $i<50) $reString .= $body[$i];
else{
@$ntag = strtolower($body[$i].$body[$i+1].$body[$i+2]);
if($ntag==”$maxpos) ){
$dd = mt_rand(1,4);
$emname = $rndem[$dd];
$dd = mt_rand(1,$totalitem);
$rnstr = $rndstring[$dd];
if($emname!=”font”) $rnstr = ” <$emname class=”$rndstyleName”>$rnstr “;
else $rnstr = ” $rnstr “;
$reString .= $rnstr.$body[$i];
$prepos = $i;
}
else $reString .= $body[$i];
}
}
unset($body);
return $reString;
}//函數結束


尋找


以下為引用的內容:
function the_content(



將這段代碼


以下為引用的內容:
function the_content($more_link_text = “(more…)”, $stripteaser = 0, $more_file = “”) {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters(”the_content”, $content);
$content = str_replace(”]]>”, “]]>”, $content);
echo $content;
}



改成


以下為引用的內容:
function the_content($more_link_text = “(more…)”, $stripteaser = 0, $more_file = “”) {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters(”the_content”, $content);
$content = str_replace(”]]>”, “]]>”, $content);
$content = RndString($content);
echo $content;
}


注意,就多了行 $content = RndString($content);

上傳附件中的RndString.php 檔案到wp-includes/下


附件: 點這裡下載

原文地址:http://www.mylb.net.cn/2008/08/608.html

http://www.bkjia.com/PHPjc/364026.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/364026.htmlTechArticle開啟 wp-includes下的post-template.php 先將代碼加到 post-template.php 第一行 以下為引用的內容: function RndString($body) { //最大間隔距離(如果在檢測不...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.