如何仅在指定服务器上运行php脚本 - 基于IP或域名?

发布于 2024-12-14 23:58:26 字数 46 浏览 3 评论 0原文

你知道有什么方法可以做到这一点吗?我想确保我的脚本仅在一个地方运行。是否可以?

Do you know any ways to do that? I want to secure my script to run only in one place. Is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

紫罗兰の梦幻 2024-12-21 23:58:26

可能最简单的方法是检查硬件标识符,例如网卡的 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.

黯淡〆 2024-12-21 23:58:26
if ($_SERVER['SERVER_ADDR'] == "127.0.0.1" && $_SERVER["HTTP_HOST"] == "mydomain.com") {
   //execute script
}
if ($_SERVER['SERVER_ADDR'] == "127.0.0.1" && $_SERVER["HTTP_HOST"] == "mydomain.com") {
   //execute script
}
原来是傀儡 2024-12-21 23:58:26

不清楚的问题。

  1. 如果您的意思是要限制每个人都可以访问您的脚本。并且只能由基于其 IP 的特殊用户访问。然后您可以使用 $_SERVER['REMOTE_ADDR'] 检查用户 IP。但是您需要注意,如果您的用户位于代理后面,您将需要检查 X-Forwarded-For HTTP 标头,然后检查 $_SERVER['REMOTE_ADDR'] 。更好的解决方案是通过设置 iptable 设置来使用服务器上的防火墙。

  2. 如果您的意思是您根本不希望任何人都可以访问您的脚本,请将代码放在 DocumentRoot 之外并从 CLI 运行它。

请提供更多详细信息,以便得到更好的答复。

Not clear question.

  1. 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 check X-Forwarded-For HTTP header then to check $_SERVER['REMOTE_ADDR']. Better solution would be to use a firewall on the server by setting iptable settings.

  2. 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.

征棹 2024-12-21 23:58:26

“noob”选项:

if ($_SERVER['SERVER_ADDR'] == "127.0.0.1" && $_SERVER["HTTP_HOST"] == "mydomain.com") {
   //execute script
}

no 非常酷,因为您可以这样做:

<?php
    $_SERVER['SERVER_ADDR'] = '127.0.0.1'; // or IP restricted
    $_SERVER['HTTP_HOST'] == 'mydomain.com'; // Or TLD restricted
    // AFTER, you do include():
    require_once('script_of_programmer.php');
?>

在这种情况下,任何脚本都可以在任何服务器中执行...

唯一的选项是使用 IonCube 或 ZEND GUARD

The option of "noob":

if ($_SERVER['SERVER_ADDR'] == "127.0.0.1" && $_SERVER["HTTP_HOST"] == "mydomain.com") {
   //execute script
}

no is very cool becouse you can do this:

<?php
    $_SERVER['SERVER_ADDR'] = '127.0.0.1'; // or IP restricted
    $_SERVER['HTTP_HOST'] == 'mydomain.com'; // Or TLD restricted
    // AFTER, you do include():
    require_once('script_of_programmer.php');
?>

in this context, any script can do executed in any server...

Unique option is use IonCube or ZEND GUARD

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文