PHP 怎樣防盜鏈代碼實現
<?php/*使用方法:將上述代碼保存為dao4.php,比如測試用的validatecode.rar在站點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/'; //下載地點1$ADMIN[’url_2’] = ''; //下載地點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]');}?>
相關文章:
1. php網絡安全中命令執行漏洞的產生及本質探究2. 三個不常見的 HTML5 實用新特性簡介3. Angular獲取ngIf渲染的Dom元素示例4. php面向對象程序設計介紹5. ASP調用WebService轉化成JSON數據,附json.min.asp6. 無線標記語言(WML)基礎之WMLScript 基礎第1/2頁7. 使用.net core 自帶DI框架實現延遲加載功能8. Warning: require(): open_basedir restriction in effect,目錄配置open_basedir報錯問題分析9. php測試程序運行速度和頁面執行速度的代碼10. ASP.NET Core 5.0中的Host.CreateDefaultBuilder執行過程解析
