Created
December 25, 2012 13:19
-
-
Save peterrus/4373208 to your computer and use it in GitHub Desktop.
random imgur image selector (quite a dirty approach)
issues:returns ocassionaly 404's while the image in fact exists
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 | |
//random imgur image selector (quite a dirty approach) | |
//issues:returns ocassionaly 404's while the image in fact exists | |
$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; | |
while(true) { | |
//variables | |
$shuffled = str_shuffle($str); | |
$trimmed = substr($shuffled, -5); | |
$header = get_headers("http://i.imgur.com/" . $trimmed . ".jpg"); | |
if(($header[0] == "HTTP/1.0 200 OK" || $header[0] == "HTTP/1.1 200 OK") && array_search('Content-Length: 503', $header) == false){ | |
header('Location: http://i.imgur.com/' . $trimmed . '.jpg'); | |
unset($trimmed, $header, $shuffled); | |
die(); | |
} else { | |
unset($trimmed, $header, $shuffled); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment