Do you know alternative of this option in WordFence?

mader

Well-known member
Babiato Lover
Trusted Seller
Trusted Uploader
Sep 18, 2019
519
372
63
Can anyone help?
I need to use similar option to "block IPs that access these URLs" which is built-in Wordfence plugin.
I do not want to use Wordfence
Did a broad research but can not find any alternative plugin or how to self code a similar "honeypot".

I need when someone visits a pre-defined url i.e. site.com/do-not-visit
than the IP address of that person/bot to be auto blocked from accessing the website.

Any ideas ?
 

Knights

Member
Mar 7, 2021
57
29
18
I'm not sure about a WordPress security plugin. However, you can achieve this by creating a php file on your server, then setting up a redirect within WordPress/SEO Plugin, htaccess etc. to direct them to the php file once someone visits: "site.com/do-not-visit" --> "site.com/block.php"

Inside your block.php, you will need to log the IP address first of all:
Code:
<?php
    $at = $_SERVER['REMOTE_ADDR'];
    // This will create a blockedips.txt on your server
    $log = file_get_contents("blockedips.txt");
    $log = trim($log); // removes leading/trailing blank lines
    $log = explode("\n", $log);
    $log[] = $at;
    $log = array_unique($log);
    $log = implode("\n", $log);
    file_put_contents("blockedips.txt", $log);

    // Show a message?
    echo "Access Denied";
?>

Then you can add this into your theme header to read the file.
Code:
<?php
    $ipArray = file('blockedips.txt', FILE_IGNORE_NEW_LINES);
    $allowed = true;
    foreach ($ipArray as $ipTest) if ($_SERVER['REMOTE_ADDR'] == $ipTest) $allowed = false;
    // Block them if they are in the file
    if ($allowed != true) {
    header('HTTP/1.0 403 Forbidden');
    die();
}
?>

Finally, add your paths to the ''robots.txt'' to prevent bots crawling and getting blocked:
Code:
User-agent: *
Disallow: /block.php
Disallow: /do-not-visit/

Edit: You could also use RewriteMap if you have a compatible server
 
Last edited:
  • Like
Reactions: mader

mader

Well-known member
Babiato Lover
Trusted Seller
Trusted Uploader
Sep 18, 2019
519
372
63
Thank you, this sounds plausible I am going to try it out!
 
  • Like
Reactions: Knights

Forum statistics

Threads
69,481
Messages
909,912
Members
239,734
Latest member
Topzttst

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu