大家知道$_session['http_referer']可以获取当前链接的上一个连接的来源地址,即链接到当前页面的前一页面的 url 地址,可以做到防盗链作用,只有点击超链接(即) 打开的页面才有http_referer环境变量, 其它如 window.open()、 window.location=...、window.showmodelessdialog()等打开的窗口都没有http_referer 环境变量。
写个函数吧 简单的可以、起到防盗链作用
function checkurl(){
//如果直接从浏览器连接到页面,就连接到登陆窗口
立即学习“PHP免费学习笔记(深入)”;
//echo "referer:".$_SESSION['HTTP_REFERER'];
if(!isset($_SESSION['HTTP_REFERER'])) {
header("location: login");
exit;
}
$urlar = parse_url($_SESSION['HTTP_REFERER']);
//如果页面的域名不是服务器域名,就连接到登陆窗口
if($_SERVER['HTTP_HOST'] != $urlar["host"] && $urlar["host"] != "202.102.110.204" && $urlar["host"] != "http://blog.163.com/fantasy_lxh/") {
header("location: login.php");
exit;
}
}
checkurl()
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号