Skip to content

Instantly share code, notes, and snippets.

@aerouk
Created July 10, 2014 16:42
Show Gist options
  • Save aerouk/af0e35db88a97033493a to your computer and use it in GitHub Desktop.
Save aerouk/af0e35db88a97033493a to your computer and use it in GitHub Desktop.
Untested self-hosted linkr script
<?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