Created
July 10, 2014 16:42
-
-
Save aerouk/af0e35db88a97033493a to your computer and use it in GitHub Desktop.
Untested self-hosted linkr script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* linkr self-hosted shortener | |
* © aerouk 2014 | |
*/ | |
$key = "your key"; | |
$err = "/path/to/404"; // public_html/* | |
if ( ! isset($_GET['url'])) showError($err); | |
checkURL($_GET['url']); | |
function checkURL($url, $key) | |
{ | |
global $err; | |
$result = json_decode(file_get_contents("https://api.linkr.pw/v3/lookup?key=$key&short=$url"), true); | |
if (isset($result['error'])) { | |
showError($err); | |
} elseif (isset($result['link'])) { | |
header("Location: https://linkr.pw/$url", true, 301); | |
die(); | |
} else { | |
showError($err); | |
} | |
} | |
function showError($err) | |
{ | |
@include_once($_SERVER['DOCUMENT_ROOT'] . $err); | |
die(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment