Last active
October 11, 2015 21:01
-
-
Save AjayAjaal/a91a6f70e8e1196a6ff8 to your computer and use it in GitHub Desktop.
Simple URL Shortener in PHP
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 | |
// 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"); | |
} |
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
fb = https://www.facebook.com/ | |
twitter = https://www.twitter.com/ | |
github = https://www.github.com/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment