Skip to content

Instantly share code, notes, and snippets.

@AjayAjaal
Last active October 11, 2015 21:01
Show Gist options
  • Save AjayAjaal/a91a6f70e8e1196a6ff8 to your computer and use it in GitHub Desktop.
Save AjayAjaal/a91a6f70e8e1196a6ff8 to your computer and use it in GitHub Desktop.
Simple URL Shortener in PHP
<?php
// load the links & Slugs from the file they're stored in
$links = parse_ini_file('links.ini');
// get the slug and remove any / characters
$slug = str_replace('/', '', $_SERVER['PATH_INFO']);
// check if the slug exists and if it corresponds to a link
if(isset($slug) && array_key_exists($slug, $links)){
// get the link corresponding to the slug
header('Location: ' . $links[$slug]);
} else {
// just send them to the default page
header('Location: ' . "http://www.ajayajaal.com");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment