Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder RexxCrow's Avatar
    Join Date
    Jul 2006
    Location
    California
    Posts
    275
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Confirmation on this code for a Dynamic Signature

    Ok to start, I have tweeked this code I found from online tutorials, though I am limited in my knowledge of PHP and unable to test this myself as apparently Apache is required and my server package (WinPro) uses IIS. However, I am making this for an Admin for a site that does use Apache, I just won’t be able to test anything myself, if I have errors in this code it would be outstanding if a PHP coder could please advise me of them along with the best method of operation, (if anybody is willing to do so.) I may not have understood everything fully, as this is the first time that I have actually played around with PHP code, as I myself am working on learning HTML, CSS, JS, and SQL at this time.

    I am putting the whole process here to give you the entire picture of what I am attempting to achieve, so if it seems like overkill, that is why, (the PHP is near the end portion of this post.) I am planning on setting these files in directory labeled: POAN, server side; this directory will also contain an HTML file that is used by the script I am trying to make this sig for. I have included these files to help paint the picture and limit any confusion. This is to work by having a script create the POAN.HTML and PC.TXT files those are then FTP'ed to the server, the POAN.HTML will be accessed by players and the PC.txt is just for the sig, these files will be updated at a set period of time by the admin. the sig will then be linked to by the games support site and the Admins own site, etc. This is for an old online door game known as TradeWars 2002 now TradeWars 2002/TWGS, the script is for a helper called TWXProxy that allows users to make scripts to automate game play for them. This project I am working on though is more admin related, though to the players benefit. Thanks again for any assistance.

    POAN Monitor.TS
    [This is just an example of the code used by TWXProxy to create the needed file for PC.TXT locally on the admins computer prior to FTPing to their website (these are excerpts from the file, as they are actually written throughout the file in various functions.)]
    Code:
    # sets up the file path and name to be used:
    setVar $sigPath $POANPath & "PC.TXT"
    
    # if no users are online:
    setVar $sig "None"
    
    # else $X is the number of users online.
    setVar $sig $X
    
    # checks for the old file, removes it and writes a new one PC.TXT:
    fileExists $fc $sigPath
    IF $fc
     DELETE $sigPath
    END
    WRITE $sigPath $sig
    POAN.HTML
    [displays the game and player information via website]

    PC.TXT
    [contains the number of players currently online, so this would just contain a number i.e. 10 (I put a little function at the bottom of the Sig.JPG file, which I modified from the random quote code, to read from this file so not sure if I have this correct? Also, does the CHMOD setting for this file matter to make this work?)]
    Code:
    10
    verdana.ttf
    [obvious]

    .htaccess file:
    Code:
    AddHandler application/x-httpd-php .JPG
    Sig.JPG file:
    Code:
    <?php
    Header('Content-type: image/jpeg');
    Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
    Header('Pragma: no-cache');
    
    // set the dimensions
    $img_width = 200;
    $img_height = 25;
    
    // create the image
    $image = imagecreate($img_width, $img_height);
    
    // set the colours
    $cool  = imagecolorallocate($image, 81, 86, 96);
    $green = imagecolorallocate($image, 0, 255, 0);
    
    // set the background colour
    // number or is top left pixel x, top left pixel y, bottom right pixel x, bottom right pixel y
    imagefilledrectangle($image, 0, 0, $img_width, $img_height, $cool);
    
    // set the font and print text
    $font = 'verdana.ttf';
    
    // reading from the Player Count text file to obtain the number of players currently online.
    // Still need to change CHMOD to 777 also?
    $count = file('PC.txt');
    
    // now i will create a line with font size 10, with no angle, 10 pixels to the right, and 15 pixels down
    ImageTTFText ($image, 10, 0, 10, 17, $green, $font, "Total Players Currently Online: ".$count);
    
    // output and destroy
    imagepng($image);
    imagedestroy($image);
    ?>
    This is the basic result I am hoping for (except in lime green):

    Total Players Currently Online: 10


    As and alterative option how would you make the number a different color? just put a defined color $ as:

    $white=imagecolorallocate($image, 255, 255, 255);
    ImageTTFText ($image, 10, 0, 10, 17, $green, $font, "Total Players Currently Online: ".$white.$count);

    (?)

    Finally the link to the Sig from the forums:

    [ CENTER ][ URL="HTTP://WebsiteAddress.EXT/POAN/POAN.HTML" ][ IMG ]HTTP://WebsiteAddress.EXT/POAN/Sig.JPG[ /IMG ][ /URL ][ /CENTER ]


    Also, for future note is there any work around or alternative to use something like this within IIS? As placing a .htaccess file in the direcotry only gives a HTTP 500 error in IIS. Again many thanks for your time.
    Last edited by RexxCrow; 11-20-2006 at 12:05 AM.

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    the .htaccess is the file that IIS won't like. All you have to do is change sig.jpg to sig.php and link to it in forums by:
    [ CENTER ][ URL="HTTP://WebsiteAddress.EXT/POAN/POAN.HTML" ][ IMG ]HTTP://WebsiteAddress.EXT/POAN/Sig.php[ /IMG ][ /URL ][ /CENTER ]

    If forums won't allow that as an image, you'll have to change what your server thinks of .jpg files. Set it to parse them as php.

    To do this in IIS you need to (as far as I know):

    open IIS
    right click on the folder containing your sig.jpg file
    select 'properties'
    click on the 'http headers' tab
    click 'file types' in the 'MIME map' section
    add a new type with

    Associated extension: .jpg
    Content type (MIME): application/x-httpd-php

    Hope that helps.

  • #3
    Regular Coder RexxCrow's Avatar
    Join Date
    Jul 2006
    Location
    California
    Posts
    275
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Outstanding and thanks much, that is a good trick to know, heh!

    BTW, can I assume that my modded PHP is correct in how it should function then?

    Sig.JPG file:
    Code:
    <?php
    Header('Content-type: image/jpeg');
    Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
    Header('Pragma: no-cache');
    
    // set the dimensions
    $img_width = 200;
    $img_height = 25;
    
    // create the image
    $image = imagecreate($img_width, $img_height);
    
    // set the colours
    $cool  = imagecolorallocate($image, 81, 86, 96);
    $green = imagecolorallocate($image, 0, 255, 0);
    
    // set the background colour
    // number or is top left pixel x, top left pixel y, bottom right pixel x, bottom right pixel y
    imagefilledrectangle($image, 0, 0, $img_width, $img_height, $cool);
    
    // set the font and print text
    $font = 'verdana.ttf';
    
    // reading from the Player Count text file to obtain the number of players currently online.
    // Still need to change CHMOD to 777 also?
    $count = file('PC.txt');
    
    // now i will create a line with font size 10, with no angle, 10 pixels to the right, and 15 pixels down
    ImageTTFText ($image, 10, 0, 10, 17, $green, $font, "Total Players Currently Online: ".$count);
    
    // output and destroy
    imagepng($image);
    imagedestroy($image);
    ?>
    This is the basic result I am hoping for (except in lime green):


    Total Players Currently Online: 10


    As and alterative option how would you make the number a different color? just put a defined color $ as:

    $white=imagecolorallocate($image, 255, 255, 255);
    ImageTTFText ($image, 10, 0, 10, 17, $green, $font, "Total Players Currently Online: ".$white.$count);
    Last edited by RexxCrow; 11-20-2006 at 08:41 PM.

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You will have to define white and green as colours and do this:

    PHP Code:
    ImageTTFText ($image1001017$green$font"Total Players Currently Online: ");

    ImageTTFText ($image100, *, 17$white$font$count);
    // replace the * with the number of pixels between the left side of the image and the start of the number 

  • #5
    Regular Coder RexxCrow's Avatar
    Join Date
    Jul 2006
    Location
    California
    Posts
    275
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Alright, wow that seems so simple to, thanks for your help... again.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •