Guide : Dynamic Signatures

Discussion in 'Graphic Design' started by SPeedY_B, Apr 30, 2003.

  1. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    A few people have asked me about this one since I first used it a while back, and now that I've had my play, I'm going to share it with everyone else :)

    Requirements :
    • A mild knowledge of php helps, but isn't essential
    • More than one signature image in gif or jpeg format
    • Webhost supporting the php hypertext processor language
    • Pie

    There are two (2) ways to get this done, either upload everything as we go along, or create the folder locally then upload it all at once, either way, the concept is still the same.


    Step 1
    Create a new folder, for the purpose of demonstration we'll call it sig
    So once uploaded, this will be accessable via http://yoursite.com/sig/


    Step 2
    next create an empty text file, and copy the following code into it.

    -------------start code------------------
    <?php
    srand( time() );
    $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 );
    ?>
    --------------end code------------------

    Re-name that file to index.php and put it in the folder we created, so that it can eventually be accessed via http://yoursite.com/sig/index.php


    Step 3
    Next upload a few images with either .gif or .jpg extensions into the /sig/ folder

    so for example the folder contents now look something like this:
    • index.php
    • sig01.jpg
    • picture.gif
    • something.gif
    • pie.jpg


    Step 4
    Now on the forums, open up your User CP and use the tags as you usually would, but instead link to the .php file like so
    [b][img]http://yoursite.com/sig/index.php[/b]


    If everything has gone according to plan, then your signature should change nearly every time the page is refreshed/viewed.



    Note : Because I don't trust the forums parsers, the source code has been attached in a text file, if you want to you can simply save this file ane remove the .txt extension to save copy pasting into a new file




    -
     
  2. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    Excellent! Thanks SpeedY :)
     
  3. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    No problem, I did say that I'd give everyone the source once I'd had my play, so I have ;)

    If people decide to use this tho, bear in mind that the images will not be cached, so try and use a reletively small sized image so that the dial-up users don't have to download a large file everytime they view a thread with your sig on.
     
  4. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    This is SPeedY_Bs sig code with sig blocker, if other people want to be able to do this

    PHP:
    <?php
    mysql_pconnect
    ("myhost","myuser","mypassword");
    mysql_select_db("mydb");
    $addr $_SERVER['REMOTE_ADDR'];
    $test mysql_query("SELECT * FROM sig");
    $dns 0;
    while(
    $check mysql_fetch_array($test))
    {
        if(
    $check['ip'] == $addr)
        {
            
    $dns 1;
        }
    }
    if(
    $dns == 0) {
        
    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" );
        
    readfile("blocked/blocked.jpg");
    }
    ?>
    all the IPs which dont want the sig are stored in the `sig` table in a MySQL database

    PHP:
    $dns 0;
    while(
    $check mysql_fetch_array($test))
    {
        if(
    $check['ip'] == $addr)
        {
            
    $dns 1;
        }
    }
    I used that because I couldnt get
    PHP:
    if(!$test) {
    // execute random sig
    } else {
    // show blocked
    }
    to work, dunno why
     
  5. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    Someone sticky this thread :)
     
  6. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    Done.
     
  7. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    Really nice tutorial.
     
  8. xsivforce

    xsivforce Prodigal Son Folding Team

    Messages:
    8,547
    Location:
    Texas, USA
    I beleive it was originaly @ x-istence.com ;)
     
  9. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    It was?
     
  10. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    Yeah definatly use the attachment..

    Pardon?
     
  11. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    Hmm, still doing the same... what the jimmy j have I done ?
     
  12. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    You've broke it all :p

    It's working fine here :)
     
  13. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    Try, this one, saved in UTF-8, should work without any problems
     
  14. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    Not that i know off. Speedy_B only asked if there was some way he could improve it. Which there isnt.
     
  15. wadada

    wadada Moderator

    Messages:
    707
    Location:
    netherlands
    . . .

    kewl :) lol im so newbie with this php code :(
     
  16. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    Re: . . .

    You shall learn, my son. It's quite fun to do.
     
  17. gonaads

    gonaads Beware the G-Man Political User Folding Team

    Now I gotta make up some Sigs and try it out :D
     
  18. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    Just get a huge collection of all your sigs over from the past :D
     
  19. gonaads

    gonaads Beware the G-Man Political User Folding Team

    That is alot :p
     
  20. Grandmaster

    Grandmaster Electronica Addict Political User Folding Team

    Messages:
    10,574
    Location:
    Santa Clara, CA
    cool tutorial :D