Skip to content

Instantly share code, notes, and snippets.

@peterrus
Created December 25, 2012 13:19
Show Gist options
  • Save peterrus/4373208 to your computer and use it in GitHub Desktop.
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
<?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