简体   繁体   English

如何让 ip 在我的 htaccess 中与允许/拒绝一起使用(使用 php)

[英]How to get the ip to use with allow/deny in my htaccess (with php)

How do I get the IP, with PHP, that I have to use for my htaccess to allow specific domains access to my content?如何获得 IP 和 PHP,我必须将其用于我的 htaccess 以允许特定域访问我的内容?

I used gethostbyname($_SERVER['HTTP_HOST']) to get the ip, but that seems not to be the right one?我使用gethostbyname($_SERVER['HTTP_HOST'])来获取 ip,但这似乎不是正确的? Or maybe something is wrong with my .htaccess file?或者我的 .htaccess 文件可能有问题?

Order deny,allow
Deny from All
Allow from 77.111.240.115

I now see that there are a lot websites hosted on this IP, is there a way to get this working?我现在看到这个 IP 上托管了很多网站,有没有办法让它工作?

You did mentioned that you are looking to just allow specific domains to access your website.您确实提到您希望只允许特定域访问您的网站。

Try this in your .htaccess and it won't require you to deal with IPs etc.在您的 .htaccess 中试试这个,它不需要您处理 IP 等。

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} 
!^http(s)?://(www\.)?yoursite.com [NC]
RewriteCond %{HTTP_REFERER} 
!^http(s)?://(www\.)?othersite.com [NC]
RewriteRule \.(jpg|jpeg|png|gif|html|php)$ - [F]

The above thing will allow access to your own website and that other website to files like jpg gif html etc.上述内容将允许访问您自己的网站和其他网站以访问 jpg gif html 等文件。

If you want you can add other file extensions in it and if you want you can add other websites in it.如果您愿意,您可以在其中添加其他文件扩展名,如果您愿意,您可以在其中添加其他网站。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM