如何仅在指定服务器上运行php脚本 - 基于IP或域名?
你知道有什么方法可以做到这一点吗?我想确保我的脚本仅在一个地方运行。是否可以?
Do you know any ways to do that? I want to secure my script to run only in one place. Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
可能最简单的方法是检查硬件标识符,例如网卡的 MAC 地址,并使用 Ion Cube 等工具对 PHP 代码进行加密,这样就无法简单地编辑 PHP 并更改 MAC 地址检查过。
possibly the easiest way to do this would be to check a hardware identifier, such as the network card's MAC address, and encrypt the PHP code using something such as Ion Cube so that someone can't simply edit the PHP and change the MAC address being checked for.
不清楚的问题。
如果您的意思是要限制每个人都可以访问您的脚本。并且只能由基于其 IP 的特殊用户访问。然后您可以使用
$_SERVER['REMOTE_ADDR']
检查用户 IP。但是您需要注意,如果您的用户位于代理后面,您将需要检查X-Forwarded-For
HTTP 标头,然后检查$_SERVER['REMOTE_ADDR']
。更好的解决方案是通过设置iptable
设置来使用服务器上的防火墙。如果您的意思是您根本不希望任何人都可以访问您的脚本,请将代码放在
DocumentRoot
之外并从 CLI 运行它。请提供更多详细信息,以便得到更好的答复。
Not clear question.
If you mean that you want to restrict your script from being accessible for everyone. And only accessible by special users based of their IP. Then you can use
$_SERVER['REMOTE_ADDR']
to check for the user IP. However you need to be aware that in cases your user is behind proxy you will need to checkX-Forwarded-For
HTTP header then to check$_SERVER['REMOTE_ADDR']
. Better solution would be to use a firewall on the server by settingiptable
settings.If you mean that you don't want your script to be accessible at all for anyone, then put the code out-side
DocumentRoot
and run it from CLI.Please provide more details to have a better answer.
“noob”选项:
no 非常酷,因为您可以这样做:
在这种情况下,任何脚本都可以在任何服务器中执行...
唯一的选项是使用 IonCube 或 ZEND GUARD
The option of "noob":
no is very cool becouse you can do this:
in this context, any script can do executed in any server...
Unique option is use IonCube or ZEND GUARD