dongyue4964 2014-03-11 00:34
浏览 115
已采纳

PHP:使用http referer添加安全性[重复]

This question already has an answer here:

Im Kinda A Noob With PHP,
I want to keep my page accessible only from a link
etc. I only want to allow people who clicked a link to my page from example.com
and others like from google.com to redirect to another page on my site etc. a error message
How Could I Do This?

</div>
  • 写回答

1条回答 默认 最新

  • dtc88867 2014-03-11 00:43
    关注
    if(isset($_SERVER['HTTP_REFERER']))
        $referer_host = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
    else
        $referer_host = '';
    if($referer_host != 'example.com')
    {
        header('Location: http://example.com/error');
        exit;
    }
    

    People not sending (correct) referers for various reasons will be entirely excluded from your page.

    Of course bookmarking your site etc. will also not work.

    As headers can be faked by the client at will, I would not call this a "security" feature.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案