Deprecated: Required parameter $parentPath follows optional parameter $classPrefix in /home/sjsmmx/domains/301lite.thinklabs.pl/public_html/libraries/jdom/legacy/loader.php on line 722
External redirects

External redirects

External redirects are possible via the API. To redirect you need to upload a php file with the following content. Thanks to which it will be possible to perform redirection as if the 301lite system was installed on another / other servers.

A sample file is provided below.

<?php

// 301lite_ver_1_2

// getting a shortcut from an address. if not sent, set 'someShort'
$short = isset($_REQUEST['short'])?$_REQUEST['short']:"someShort";

// fetching language from address. if not sent set 'pl';
$rlang = isset($_REQUEST['lang'])?$_REQUEST['lang']:"pl";

// getting the language from the User's browser.
$lang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])?substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2):$rlang;

// url where the 301lite system is installed
$sysUrl = "http://twojadomena.pl";

// API uri
$apiUrl = $sysUrl . "/api/get/url/";

// API key
$apiKey = "twoj_klucz_api";

// getting the address from which the User came, if set, or the server address
$refererUrl = isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'http://'.preg_replace('#/.*#', '', $_SERVER['SERVER_NAME']);

// getting the User's IP address
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $rip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $rip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $rip = $_SERVER['REMOTE_ADDR'];
}

// getting destination address for shortcut $short with language $lang
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_REFERER, $refererUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_POSTFIELDS, array("short"=>$short,"lang"=>$lang,"apikey"=>$apiKey,"referer_ip"=>$rip));

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

$dane = json_decode($strona);

// checking if the IP address is on the spam list. if not a redirect is done
// if it is a redirection to a page with a captcha form
if ($dane->spam->ip->appears==0){
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: ".$dane->url, true, 301);
    exit;
} else {
    header("Location: ".$sysUrl."/captcha/?target=".urlencode(base64_encode($short))."&r=".urlencode(base64_encode($refererUrl)), true, 301);
    exit;
}
?>
# reguły pliku .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^r\/([0-9a-zA-z_\-]+)$ 301lite.php?short=$1 [L]
</IfModule>

 

301lite - redirect with API (video instruction)

©2024 Thinklabs.pl. All Rights Reserved.

Search