如何从我自己的域/服务器调用我的PHP脚本



我有这个php脚本:

include 'include.php';

脚本将在http://ppyazi.com/twitterimg.php上。因此,人们将在其他域上运行此脚本:

<img src="http://ppyazi.com/twitterimg.php?id=QuixD3V" class="logo" />

我希望php包括脚本仅在http://ppyazi.com/twitterimg.php时运行.com或其中的任何文件/目录都不运行脚本。

您可以使用http_referer限制热链接

将其添加到您的php

简单示例:

strstr($_SERVER['HTTP_REFERER'], 'ppyazi.com') or exit('denied');
// ... some codes that renders image
// e.g
// header('Content-Type: image/png');
// echo file_get_contents('image_file.png');

复杂示例:

/**
 * Returns boolean (true/false)
 * @param  string $sHostName Provide hostname
 * @return bool
 */
function isHost($sHostName) {
    return strstr($_SERVER['HTTP_REFERER'], $sHostName);
}
if (isHost('ppyazi.com') === true) {
    // do something you want if your domain is on ppyazi.com
} else {
    // remove something you want if you are out of ppyazi.com
}

我的主机甚至不再提供$_SERVER['HTTP_REFERER'],因为它很容易欺骗。当我需要使用php检查我自己的服务器的某些东西时,我会检查以下内容:

if($_SERVER['REMOTE_ADDR'] !== $_SERVER['SERVER_ADDR']) {
    // we have a match so go forth
    }

我不使用它作为我唯一需要安全的检查,但是作为首次检查,它肯定会有所帮助,以防止眼睛和蜘蛛触发其余的脚本。尽管共享服务器上的另一个站点可能会使用相同的IP。我正在使用VPS,所以这对我而言并不关心。如果有人在使用我的服务器上使用另一个网站窥探,那么我有更大的问题要处理。

最新更新