Last active
November 6, 2020 11:25
-
-
Save CBeloch/cc154aafe7b739f334e9 to your computer and use it in GitHub Desktop.
Giphy - Random GIF by Tag
This file contains hidden or 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
# 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] |
This file contains hidden or 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 | |
// 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