代码之家  ›  专栏  ›  技术社区  ›  dLehr

如何在.txt文件中阻止某些页面

  •  0
  • dLehr  · 技术社区  · 8 年前

    如果页面位于.txt文件中,如何阻止(重定向)页面:

    我有这个片段-好消息是块中的url。txt将被阻止(白色站点),但我希望它重定向到/file-not-found.php

    <?php
    list($blockExist, $blockData) = array(false, null);
    
    if (is_string($blockData = @file_get_contents('/block.txt'))) {
        $blockData = preg_replace('/\s+/', '', $blockData);
    }
    
    if (isset($_SERVER['REQUEST_URI'])) {
        $httpLink = explode('?', $_SERVER['REQUEST_URI']);
        $httpLink = $httpLink[0] == '/' ? null : $httpLink[0];
    }
    
    if ($blockData != null && $httpLink != null && stripos("{$blockData}http://", "{$httpLink}http://") !== false) {
        $blockExist = true;
    }
    
    if ($blockExist) {
        require_once dirname(__FILE__) . '/file-not-found.php';
        exit;
    }
    ?>
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   Jigar Patel    8 年前

    请尝试以下代码。。

    //require_once dirname(__FILE__) . '/file-not-found.php'; 
    header('Location: http://www.example.com/file-not-found.php');
    

    感谢