Guide: Dynamic Signatures.

Discussion in 'Graphic Design' started by SPeedY_B, Feb 28, 2005.

  1. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    Only smurfs know where the original thread went, so here it is again just for reference sake.

    To get yourself a dynamic signature, first you need a proper host which supports both PHP and hotlinking. Most free hosts do not offer this and won't work at all, check with your host before trying to use this script, else you may end up wasting your time.

    Create a folder on your host called 'sigs' (or whatever you want really) then pop the following code into your favourite text editor and save the file as 'sig.php' or any other name you like.
    PHP:
    <?php
    ob_start
    'ob_gzhandler' );
    srandtime() );
    $files = array();
    if (
    $dir = @opendir(".")) {
    while ((
    $file readdir($dir)) !== false) {
    if ( 
    eregi'.(jpg|gif|png)$'$file ) ) {
    $files[] = $file;
    }
    }
    closedir($dir);
    }
    $file $files[rand() % sizeof$files )];
    if ( 
    eregi'.jpg$'$file ) ) { header"Content-Type: image/jpeg" ); }
    elseif ( 
    eregi'.gif$'$file ) )  { header"Content-Type: image/gif" ); }
    else { 
    header"Content-Type: image/png" ); }
    header"Content-Length: " filesize$file ) );
    readfile$file );
    ?>
    upload this to your host in the folder we just created, fill the folder with the images of your choice (being jpeg, gif or png files) and then hotlink the file in your signature using the following code:

    [​IMG]

    substituting the domain for your own, of course.

    Couresy of Geffy we also have a dynamic signature with IP blocking so certain IP's can be prevented/saved from viewing the images which is handy for those on dial-up, and also for those who view the forums at work and don't wish to see risque images.

    PHP:
    <?php
    /**
     * MySQL Table Definition
     * 
     * CREATE TABLE `sig` (
     *     `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
     *     `ip` VARCHAR( 16 ) NOT NULL ,
     *     PRIMARY KEY ( `id` ) ,
     *     UNIQUE (
     *         `ip`
     *     )
     * );
     *
     * Script first checks to see if the IP address has been added to
     * a list of addresses which have requested not the see a random image.
     * If they have then the blocked image is shown, if not then the
     * contents of the folder which this file is in is read and an image
     * is randomly selected, the proper headers sent and then the image
     * data.
     */
    mysql_pconnect("localhost","username","password");
    mysql_select_db("database");

    $addr $_SERVER['REMOTE_ADDR'];
    $query mysql_query("SELECT `id` FROM sig WHERE `ip`='{$addr}'");
    $rows mysql_num_rows($query);

    if(
    $rows != 0) {
        
    // No rows, ip address has not requested blocking
        
    srandtime() );

        
    $files = array();
        if (
    $dir = @opendir(".")) {
            
            while ((
    $file readdir($dir)) !== false) {
                if ( 
    eregi'.(jpg|gif)$'$file ) ) {
                    
    $files[] = $file;
                }
            }
            
            
    closedir($dir);
        }

        
    $file $files[rand() % sizeof$files )];

        if ( 
    eregi'.jpg$'$file ) ) {
            
    header"Content-Type: image/jpeg" );
        } else {
            
    header"Content-Type: image/gif" );
        }

        
    header"Content-Length: " filesize$file ) );

        
    readfile$file );
    } else {
        
    header"Content-Type: image/jpeg" );
        
    header"Content-Length: " filesize("blocked.jpg"));
        
    readfile"blocked.jpg" );
    }
    ?>
    As with the previous code, simply save the file and upload it into a folder full of images, hotlink it, and you're set.

    Enjoy.
     
    Perris Calderon and vivid_vibe like this.
  2. Moonwraith

    Moonwraith Moderator Folding Team

    Messages:
    1,131
    Location:
    UK
    Thanks Speedy, was wondering where the original went :) excellent, ta
     
  3. vivid_vibe

    vivid_vibe OSNN Senior Addict

    Messages:
    406
    Very nice post, Speedy. :)
     
  4. Volomon

    Volomon OSNN One Post Wonder

    Messages:
    4
    Does anyone know any PHP hosts that will allow hotlinking? Its driving me crazy looking for a host becuase 90% of the time they don't say whether you can hotlink or not so I gotta go through the whole process of registering and testing it out over and over.

    I would EXTREMELY appreciate it if someone could help me out here.
     
  5. kcnychief

    kcnychief █▄█ ▀█▄ █ Political User Folding Team

    Messages:
    16,948
    Location:
    Massachusetts
  6. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    Free hosts usually don't allow hotlinking, I don't think that I've ever heard of a paid host not allowing it though.

    Which hosts have you been using ?
     
  7. Volomon

    Volomon OSNN One Post Wonder

    Messages:
    4
    I've been just looking for a free one, if I paid for it I would definately be a bit disappointed if they didn't let me hotlink.
     
  8. kcnychief

    kcnychief █▄█ ▀█▄ █ Political User Folding Team

    Messages:
    16,948
    Location:
    Massachusetts
    That being said, 1and1 has very competetive and cheap prices, as well as great support :)
     
  9. robry

    robry OSNN One Post Wonder

    Messages:
    9
    this is gonna help so much. thanks speedy.