NameSilo

Show random image

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

Daniel

Danltn.comVIP Member
Impact
133
Someone asked for a script that would show a random image, only took a few minutes to write, so I thought I might as well share it here.

PHP:
<?php

/**
 * Danltn | http://danltn.com/
 * No warranty is given to code used.
 * I'm scared of lawsuits.
 */

$images = array();

$images[] = 'http://www.escapistmagazine.com/global/media/images/articles/folder/120/zeropunctuation_logo.png';
$images[] = 'http://www.google.com/images/experimental.gif';
$images[] = 'http://www.w3.org/2001/tag/2007/05/TagThursDiagram1.JPG';

// Add as many as you like here.

$image = $images[rand(0, count($images) - 1)];
// Get random image.

switch (strtolower(substr($image, -4, 4)))
{
    case "jpeg":
    case ".jpg":
        $ctype = "image/jpg";
        break;
    case ".gif":
        $ctype = "image/gif";
        break;
    case ".png":
        $ctype = "image/png";
        break;
}
// Find the content type, based on the last 4 characters, I could add GDLib here, but I haven't, this was a quick script.

$file = @file_get_contents($image);
// Get the file

if ($file)
{
	// Only if the file has successfully been 'grabbed'.
    $len = strlen($file);
    // Get the length to be kind to the browser.
    if (!headers_sent())
    {
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: public");
        // Set headers.
        header("Content-Type: $ctype");
        // Set content type as correct image.
        header("Content-Length: " . $len);
        // Be kind to the browser by saying the length.

        echo $file;
        // If it all checks out, send the image.
    }
}

?>
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Appraise.net

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back