diff --git a/images/elephpants.php b/images/elephpants.php index 3375f9d10..3cee268ad 100644 --- a/images/elephpants.php +++ b/images/elephpants.php @@ -20,7 +20,7 @@ // determine how many images to serve. if (isset($_REQUEST['count'])) { - $count = intval($_REQUEST['count']); + $count = min(intval($_REQUEST['count']), 50); } else { header('HTTP/1.1 400', true, 400); print json_encode(array( @@ -46,10 +46,11 @@ if (!$photos || !is_array($photos)) { // prepare requested number of elephpants at random. shuffle($photos); $elephpants = array(); -foreach ($photos as $n => $photo) { +$got = 0; +foreach ($photos as $photo) { // stop when we have the requested number of photos. - if ($n == $count || $n > 20) { + if ($got == $count) { break; } @@ -58,6 +59,7 @@ foreach ($photos as $n => $photo) { continue; } + $got++; // add photo to response array. $elephpants[] = array( 'title' => $photo['title'], @@ -67,3 +69,4 @@ foreach ($photos as $n => $photo) { } print json_encode($elephpants); +