Skip to content

Instantly share code, notes, and snippets.



Last active Nov 29, 2016
What would you like to do?
Giphy - Random GIF by Tag
# Will allow to use a .gif extension.
# Script can now be used as
RewriteEngine on
RewriteRule ^(.*).gif giphy.php?tag=$1 [L,QSA]
$TAG = $_GET['tag'];
$API_KEY = "dc6zaTOxFJmzC"; // Public BETA Key
$REDIRECT = true; // Should the user be redirected to the gif or should it be tunneled to this page?
// Don't touch from this are unless you know what you do
$URL = "$TAG&api_key=$API_KEY";
// Make URL Request
$response = file_get_contents($URL);
$jsonResponse = json_decode($response, true);
$gifURL = $jsonResponse["data"]["image_original_url"];
if ($REDIRECT) {
header("Location: $gifURL");
} else {
header("Content-Type: image/gif");
$gifContent = file_get_contents($gifURL);
echo $gifContent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.