Skip to content

Instantly share code, notes, and snippets.

@CBeloch

CBeloch/.htaccess

Last active Nov 29, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.