Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tutorial] Rotating Signature
#1
Making your Signature Randomizer

Step 1: Get your own web host

For this step you need an actual webhosting service that supports the use of the PHP language. If you already have your website set up then you can skip this step.

Once you've set up your site (it shouldn't take too long, you normally just have to provide a username, password, website name and a contact email address for yourself. Personal details are sometimes required, but you can sometimes skip that part.) you can move on to step number 2.

Step 2: Create your directory

Once your site is set up and is running, you can create a new directory (folder) on the root of your site and call it "random.jpg." Actually you can call it whatever you like but remember to change the referenced names at the end. And yes you can create directories which have dots in them followed by extensions.

Upload all of the images which you want to be in your rotator to the "random.jpg" directory.

Also, make sure that the files which you upload are only files with the following extensions:

.jpg
.jpeg
.png
.gif

Step 4: Make the index.php file

Open up notepad or an equivalent plain text editor, it doesn't really matter which. Then copy and paste the following code into your document. For easy copy and pasting, Ctrl + Click in the white box, then press Ctrl + C.

Code:
<?php
// This script randomly selects and displays images from the current directory
// It is a stripped-down version of the Automatic Image Rotator script by Dan P. Benjamin.

// Set image filename extensions
$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';

// Get contents of current directory
$fileList = array();
$handle = opendir("./");
while ( false !== ( $file = readdir($handle) ) ) {
$file_info = pathinfo($file);
if (
     isset( $extList[ strtolower( $file_info['extension'] ) ] )
) {
    $fileList[] = $file;
}
}
closedir($handle);

if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$img = $fileList[$imageNumber];
}

if ($img!=null) {
$imageInfo = pathinfo($img);
$contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
header ($contentType);
readfile($img);
} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$im = @imagecreate (100, 100)
     or die ("Cannot initialize new GD image stream");
$background_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 0,0,0);
imagestring ($im, 2, 5, 5,  "IMAGE ERROR", $text_color);
imagepng ($im);
imagedestroy($im);
}
}

?>

Save this file as index.php and upload it into the "random.jpg" directory which you created in step 2.

Step 5: Save your rotator

Create an [IMG] tag which links to your random.jpg directory. An example is below.

Code:
[img]http://yourhost.com/random.jpg[/img]

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ...:::[TUTORIAL].htaccess - A way to keep secure[TUTORIAL]::... Sam 12 2,995 03-11-2011, 03:45 AM
Last Post: KillaMuvZ

Forum Jump:


Users browsing this thread: 1 Guest(s)