PHP 怎樣防盜鏈代碼實(shí)現(xiàn)
<?php/*使用方法:將上述代碼保存為dao4.php,比如測試用的validatecode.rar在站點(diǎn)http://www.XXXX.com里面,則用以下代碼表示下載連接.文件名?site=1&file=文件例如以下URL:http://www.XXXX.cn/dao4.php?site=1&file=validatecode.rar*/$ADMIN[’defaulturl’] = 'http://www.XXXX.com/404.htm'; //盜鏈返回的地址$okaysites = array('http://www.XXXX.com/','http://XXXX.com'); //白名單$ADMIN[’url_1’] = 'http://www.XXXX.com/download/'; //下載地點(diǎn)1$ADMIN[’url_2’] = ''; //下載地點(diǎn)2,以此類推$reffer = $HTTP_REFERER;if ($reffer) { $yes = 0; while (list($domain, $subarray) = each($okaysites)) { if (ereg($subarray, '$reffer')) { $yes = 1; } } $theu = 'url' . '_' . '$site'; if ($ADMIN[$theu] AND $yes == 1) { header('Location: $ADMIN[$theu]/$file'); } else { header('Location: $ADMIN[defaulturl]'); }} else {header('Location: $ADMIN[defaulturl]');}?>
相關(guān)文章:
1. PHP使用Swagger生成好看的API文檔2. 通過實(shí)例解析Python文件操作實(shí)現(xiàn)步驟3. Python3 json模塊之編碼解碼方法講解4. Python 利用Entrez庫篩選下載PubMed文獻(xiàn)摘要的示例5. ASP.NET MVC使用jQuery ui的progressbar實(shí)現(xiàn)進(jìn)度條6. ASP基礎(chǔ)知識VBScript基本元素講解7. Python 制作查詢商品歷史價格的小工具8. python使用jenkins發(fā)送企業(yè)微信通知的實(shí)現(xiàn)9. Python 合并拼接字符串的方法10. Python 如何調(diào)試程序崩潰錯誤

網(wǎng)公網(wǎng)安備