PHP Allow access to specific referrer url/page only

前端 未结 2 1320
悲&欢浪女
悲&欢浪女 2020-12-09 13:02

So my question is simple ive used the following method for allowing access to the php script via the referrer\'s domain name but i want to allow access for only referrers ma

2条回答
  •  眼角桃花
    2020-12-09 13:23

    It will not be safe because referrer data can be easily spoofed. However, if it still fits your needs, then you should be fine with your code already, since $_SERVER['HTTP_REFERER'] contains the full referrer URL and not just the domain. Actually, your present code needs some adjustments because it can't work like that:

    
    

    Note that if you check if HTTP_REFERER is set before checking if it's what you want, people would get to your script without any referrer set at all, so you should check it in any case. Now, checking for a specific URL is much simpler:

    
    

提交回复
热议问题