如何只允许一个特定域访问我的网站页面? [英] How do I allow only one specific domain to access my website page?

查看:111
本文介绍了如何只允许一个特定域访问我的网站页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,



我想只允许一个特定的域名访问我的一个页面。



例如:如果用户来自www.google.com,他们可以访问www.mywebsite.com/restricted_pa​​ge。



我尝试了一些使用php的推荐方式,但没有一个是非常好的。



是否可以只允许网站的IP地址访问我的网站页面?



我的尝试:



Hey,

I want to allow only one specific domain to access one of my pages.

So for example: only if the user comes from www.google.com they can access www.mywebsite.com/restricted_page.

I have tried some referrer ways using php but none that are very well made.

Is it possible to only allow the IP address of the website to access my website page?

What I have tried:

<?php
    if ($_SERVER['HTTP_REFERER'] == "https://www.whatismyreferer.com/") {
        // continue
    } else {
        header("Location: https://www.whatismyreferer.com/");
        exit(); //Stop running the script
        // go to form page again.
    }
?>

推荐答案

_SERVER ['HTTP_REFERER'] ==https:// www .whatismyreferer.com /){
//继续
}其他{
header(Location:https://www.whatismyreferer.com/);
exit(); //停止运行脚本
//再次转到表单页面。
}
?>
_SERVER['HTTP_REFERER'] == "https://www.whatismyreferer.com/") { // continue } else { header("Location: https://www.whatismyreferer.com/"); exit(); //Stop running the script // go to form page again. } ?>


如果您希望允许用户点击Google搜索结果而非其他人,则使用referer header是一个可行的选项。



请注意,浏览器不会从安全站点(例如https://google.com)发送引用标头一个不安全的网站。您应该在您的网站上启用https来执行此操作。



对于将浏览器配置为永不发送referer标头的隐私权用户而言,此选项也不是非常用户友好。
If you are looking to allow users who click on a google search result and not others, then using the referer header is a viable option.

Do note however that browsers will not send a referer header from a secure site (e.g. https://google.com) to an insecure site. You should enable https on your website to do this.

This option is also not very user-friendly for privacy-minded users who configure their browser to never send referer headers.


在连接选项卡和LAN设置中使用代理127.0.0.1
Use proxy 127.0.0.1 in connections tab and LAN settings


这篇关于如何只允许一个特定域访问我的网站页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆