SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to make dynamic signutures with stats

    I was wondering how would i make a image like
    http://www.fpstactics.com/sig/custom/killa/1912428.jpg
    I know this is coded with PHP
    But how would i make this, i think all the codes are pulled from
    http://clan.subagames.com/charstat_cf.aspx?usn=1912999
    But witch codes?

    Also how would i make a engine which would allow my users to make there own by inserting there USN? (number at the end of the link)
    Kind of like
    http://www.fpstactics.com/gaming_signatures.php

    Thanks in advance
    NOTE: I have host monster

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You fetch the contents of the page:
    PHP Code:
    $html file_get_contents("http://clan.subagames.com/charstat_cf.aspx?usn=1912999"); 
    Then use regular expressions to extract the text you want from the HTML.
    http://www.php.net/preg_match
    http://www.regular-expressions.info/tutorial.html

    Then use PHP's image manipulation functions to create the image and output it to the browser.
    http://us.php.net/gd

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey can you do a tut on how to do this? i get lost with the first link
    (For Subagames)

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The second link is a tutorial for writing patterns for the first link. If you want someone to code the whole thing for you, then put out a Looking to Hire listing in the marketplace.

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use the GD library to draw the signature:
    http://php.net/gd
    Take a look at the many examples and test them out to get the hang of how it works.

    When you know how to work the API, design something nice in your favorite graphics editor, export it to a PNG file, load it in with GD in your script, and manually position all the text and such. After you're all done, you might want to convert the PNG file to a GD file (you can do that with PHP's GD library too) for performance reasons (though I don't know if it has a noticeable effect).

    To take in a USN, you just use $_GET like you would normally. In the image you linked, it doesn't have a query part in the URL though. If you use Apache, you can use mod_rewrite to fake URLs and make them redirect to your script (#####.png => signature.php?usn=#####). Shove this into a .htaccess file:
    Code:
    RewriteEngine on
    RewriteRule ^([0-9]+)\.png$ signature.php?usn=$1 [QSA,L]
    (After you get all of this working, you want to save the signature images to disk temporarily because it's costly to have to re-generate this image every time. To save bandwidth, there are some HTTP headers that you want to send to make browsers cache your image, but you can ask about these things later.)

  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok so this is what they use for the kill count
    <tr>
    <td align="left" valign="top" class="stylenav13">Total Kills</td>
    <td align="left" valign="top"><span id="ctl00_Main_lbl_enemy_kill_cnt">9805</span></td>
    </tr>

    so would i type in

    $html = file_get_contents("http://clan.subagames.com/charstat_cf.aspx?usn=1912999ctl00_Main_lbl_enemy_kill_cnt");
    ?



    Also can someone explain the php GD and what it dose? (or link me to a more nooby guide)
    Thanks in advance

  7. #7
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No, you don't change the URL, it's not that easy.

    You write a regular expression which matches the 9805 in $html.

  8. #8
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So how do i trigger a regex? (regular expression?)

  9. #9
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    No, you don't change the URL, it's not that easy.

    You write a regular expression which matches the 9805 in $html.
    The 9805 changes so would i have to make something like
    int preg_match ( string $<td align="left" valign="top"><span id="ctl00_Main_lbl_enemy_kill_cnt">9805</span></td>
    , string $<span id="ctl00_Main_lbl_enemy_kill_cnt">
    [, array &$match[, int $flags [, int $offset ]]] )
    ?

  10. #10
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <html>
    <?php
    $html = file_get_contents("http://clan.subagames.com/charstat_cf.aspx?usn=1912428");
    $subject = "0-9";
    $pattern = '<span id="ctl00_Main_lbl_enemy_kill_cnt">9805</span>';
    preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
    print_r($matches);
    ?>
    </html>


    Sorry im spaming :3

    Ok so far i get
    Make the file name name.php
    then
    <html>
    <?php
    $html = file_get_contents("http://clan.subagames.com/charstat_cf.aspx?usn=1912428");
    ?>
    </html>
    And thats it
    Last edited by Naromaru; Apr 23, 2009 at 15:34. Reason: Upps wrong code placement


Bookmarks

Posting Permissions

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