如何在PHP中进行许可证验证

时间:2019-04-02 17:31:11

标签: php

前一段时间,我开始编写许可证验证脚本。看起来像这样:

if (! (ini_get (allow_url_fopen))) exit ('Configuration Error: allow_url_fopen must be enabled on your server');

define ("LICENSE_SERV", "https://admin.devilshield.pl/check.php?key=");

    $ LICENSE_SERV = LICENSE_SERV;
    $ LICENSE_KEY = LICENSE_KEY;
    $ licserv = "$ LICENSE_SERV $ LICENSE_KEY";
    $ lines = @file ($ licserv);

    foreach ($ lines as $ line_num => $ line) {
    $ license = htmlspecialchars ($ line);

    if ($ license == "INVALID") {echo '<div style = "font-family: Roboto, sans-serif; font-size: 14px; z-index: 100000; height: 7px; padding: 12px; color: white; position: fixed; top: -8px; left: 0; bottom: 20px; width: 100%; background: # 000000e6; text-align: center; "> Error loading AntiDDoS by DevilShield.pl v1.0! Please check the license! </ Div> ';}

这是“有效”或“无效”。如果返回值为“ INVALID”,则这是脚本下一部分的错误消息

问题是它不起作用。即使存在这样的许可证,也会始终抛出此错误

index.php:

require_once ('start.php'); <br>
define ("LICENSE_KEY", "8080-8080-8080-8080");

我将把文件扔到单独的主机上,以使此片段保留在index.php中。除了define();之外,还有其他选择吗?



附言我来自波兰,今年15岁。不幸的是,我的英语不太好,所以我使用Google翻译

1 个答案:

答案 0 :(得分:0)

尝试一下:

if (!(ini_get('allow_url_fopen'))) {
    exit('Something is wronguration Error: allow_url_fopen must be enabled on your server');
}

    define('LICENSE_SERV', 'https://admin.devilshield.pl/check.php?key=');
    define('LICENSE_KEY', 'error-8080-8080-8080-8080');

    $LICENSE_SERV = LICENSE_SERV;
    $LICENSE_KEY = LICENSE_KEY;
    $licserv = "{$LICENSE_SERV}{$LICENSE_KEY}";
    $license = file($licserv);

    if (is_array($license) && $license[0] === 'INVALID') {
        echo '
            <div style="font-family: Roboto, sans-serif; font-size: 14px; z-index: 100000; height: 7px; padding: 12px; color: white; position: fixed; top: -8px; left: 0; bottom: 20px; width: 100%; background: #000000e6; text-align: center;">
            Error loading AntiDDoS by DevilShield.pl v1.0! Please check the license!
            </div>
        ';
    }

为什么不使用 file_get_contents