Skip to content

Instantly share code, notes, and snippets.

@waltspence
Forked from CBeloch/.htaccess
Created November 29, 2016 03:07
Show Gist options
  • Save waltspence/88d22c5028a5f55810c1660e40a26245 to your computer and use it in GitHub Desktop.
Save waltspence/88d22c5028a5f55810c1660e40a26245 to your computer and use it in GitHub Desktop.
Giphy - Random GIF by Tag
# Will allow to use a .gif extension.
# Script can now be used as www.mydomain.com/pokemon.gif
RewriteEngine on
RewriteRule ^(.*).gif giphy.php?tag=$1 [L,QSA]
<?php
// CONFIGURE
$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 = "http://api.giphy.com/v1/gifs/random?tag=$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