php - How to block some Pages if in .txt file

337

How to block (redirect) a Page if the Page is in a .txt file:

I have this snippet - the good news is the url in block.txt will be blocked (white Site) but i want it to redirect to /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;
}
?>
85

Answer

Solution:

Try this code..

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

Thank

People are also looking for solutions to the problem: api - How to rename at destination in php while using dropboxapi?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.