如何在PHP程序中防止盗链
程序员文章站
2022-06-05 08:44:16
example: 页面: dl.php -------...
example:
页面: dl.php
--------------------------------------------------------------------------------------
<?php
$id = $_get['id'];
$act = $_get['act'];
switch($act) {
default :
case "display" : displayhtml(); break;
case "down" : down(); break;
}
function displayhtml($id) {
setcookie("visited", "true");
// print your html.
}
function down($id) {
if(! isset($_cookie['visited']) ) print "你盗联?";
$sql = "select path from table where id=". $id;
//..............................
}
?>
<a href="dl.php?id=1&act=down">download now...</a>
页面: dl.php
--------------------------------------------------------------------------------------
复制代码 代码如下:
<?php
$id = $_get['id'];
$act = $_get['act'];
switch($act) {
default :
case "display" : displayhtml(); break;
case "down" : down(); break;
}
function displayhtml($id) {
setcookie("visited", "true");
// print your html.
}
function down($id) {
if(! isset($_cookie['visited']) ) print "你盗联?";
$sql = "select path from table where id=". $id;
//..............................
}
?>
<a href="dl.php?id=1&act=down">download now...</a>