Jump to content

Redirect Geo IP

   (0 reviews)

Description

Redirect Geo IP

Edit index.php

<?php

$startTime = microtime(true);
$fileDir = dirname(__FILE__);

require($fileDir . '/ge0.php');
require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$fc = new XenForo_FrontController(new XenForo_Dependencies_Public());
$fc->run();

The ge0.php

<?php

// GEO Blocking

$disallowedCountries = [
    'DE'
];

$ch = curl_init('http://ipinfo.io/' . $_SERVER['REMOTE_ADDR']);
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER         => false,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_MAXREDIRS      => 10,
    CURLOPT_ENCODING       => '',
    CURLOPT_USERAGENT      => '',
    CURLOPT_AUTOREFERER    => true,
    CURLOPT_CONNECTTIMEOUT => 120,
    CURLOPT_TIMEOUT        => 120
]);

$response = curl_exec($ch);
curl_close($ch);

$json = json_decode($response, true);
if(isset($json['country']) && in_array(strtoupper($json['country']), $disallowedCountries)) {
    header("Location: http://example.com");
    exit;
}

 



Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest

Support

Support

Please enter your display name

×
×
  • Create New...

Important Information

This website uses cookies and shit. Deal with it or GTFO!