Swenn Posted August 26, 2009 Share Posted August 26, 2009 Hello, I'm a Php newbie and I got this script from someone else over 2 years ago. I don't have any contact with him anymore so he can't help me. Now what I want to create is a Dynamic Signature script. The one I got was made for the game RuneScape, it grabbed the highscores and stats from the website and displayed them on the signature. As I'm not making this script for RuneScape I don't want those things to be displayed on the signature so I removed them. I Only want a username to be displayed on the signature. The only problem is, I can't remove the function that checks if the username is in the highscores. So only usernames which are in the RuneScape highscores work. Here's what the origional script looks like: <?php function skill_list ($skillname="Overall") { $skilllist = array( "#^Overall$#si", "#^Attack$#si", "#^Defence$#si", "#^Strength$#si", "#^Hitpoints$#si", "#^Ranged$#si", "#^Prayer$#si", "#^Magic$#si", "#^Cooking$#si", "#^Woodcutting$#si", "#^Fletching$#si", "#^Fishing$#si", "#^Firemaking$#si", "#^Crafting$#si", "#^Smithing$#si", "#^Mining$#si", "#^Herblore$#si", "#^Agility$#si", "#^Thieving$#si", "#^Slayer$#si", "#^Farming$#si", "#^Runecraft$#si", "#^Hunter$#si", "#^Construction$#si", "#^Summoning$#si" ); $skillnum = array( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 ); $results = preg_replace($skilllist, $skillnum, $skillname); if($results && is_numeric($results)) { return $results; } else { return 0; } } function get_stats ($skillid="0", $lookup="0", $type="1", $data="N/A") { if($data == "N/A") { return "0"; } else { if($lookup == 0) { if($type > 3) { $type = 2; } preg_match_all("#(.*?),(.*?),(.*?)\n#s", $data, $stats); if($stats[$type][$skillid] == "-1") { return "--"; } else { return $stats[$type][$skillid]; } } else { preg_match("#(.*?),(.*?)$#", $data, $minigamestats); if($minigamestats[1] == "-1") { return "--"; } else { if($type == 1) { return $minigamestats[1]; } else { return $minigamestats[2]; } } } } } function get_page ($url="http://www.runescape.com/") { $handle = @fopen($url, "r"); if($handle) { $urldata = ""; while (!feof($handle)) { $urldata .= fread($handle, 8192); } fclose($handle); return $urldata; } else { return false; } } if(empty($_GET["name"]) || !Isset($_GET["name"])) { echo "Please enter a username."; } else { $username = $_GET["name"]; $username = str_replace(array("_", "-", "|", "+"), " ", $username); $username = ucwords(strtolower($username)); $urldata = get_page("http://hiscore.runescape.com/index_lite.ws?player=".$username); if (!$urldata) { echo $username." does not exist in the hiscores."; } else { // Output $attack = get_stats(skill_list("attack"), 0, 2, $urldata); $strength = get_stats(skill_list("strength"), 0, 2, $urldata); $defence = get_stats(skill_list("defence"), 0, 2, $urldata); $hitpoints = get_stats(skill_list("hitpoints"), 0, 2, $urldata); $ranged = get_stats(skill_list("ranged"), 0, 2, $urldata); $prayer = get_stats(skill_list("prayer"), 0, 2, $urldata); $magic = get_stats(skill_list("magic"), 0, 2, $urldata); $cooking = get_stats(skill_list("cooking"), 0, 2, $urldata); $woodcutting = get_stats(skill_list("woodcutting"), 0, 2, $urldata); $fletching = get_stats(skill_list("fletching"), 0, 2, $urldata); $fishing = get_stats(skill_list("fishing"), 0, 2, $urldata); $firemaking = get_stats(skill_list("firemaking"), 0, 2, $urldata); $crafting = get_stats(skill_list("crafting"), 0, 2, $urldata); $smithing = get_stats(skill_list("smithing"), 0, 2, $urldata); $mining = get_stats(skill_list("mining"), 0, 2, $urldata); $herblore = get_stats(skill_list("herblore"), 0, 2, $urldata); $agility = get_stats(skill_list("agility"), 0, 2, $urldata); $thieving = get_stats(skill_list("thieving"), 0, 2, $urldata); $slayer = get_stats(skill_list("slayer"), 0, 2, $urldata); $farming = get_stats(skill_list("farming"), 0, 2, $urldata); $runecraft = get_stats(skill_list("runecraft"), 0, 2, $urldata); $construction = get_stats(skill_list("construction"), 0, 2, $urldata); $summoning = get_stats(skill_list("summoning"), 0, 2, $urldata); $totall = get_stats(skill_list("Totall"), 0, 2, $urldata); $hunter = get_stats(skill_list("Hunter"), 0, 2, $urldata); //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ function combatLevel($cbattack, $cbdefence, $cbstrength, $cbhp, $cbprayer, $cbranged, $cbmagic, $cbsummoning) { $cbbase = ($cbdefence + $cbhp + floor($cbprayer / 2) + floor($cbsummoning / 2)) * 0.25; $cbmelee = ($cbattack + $cbstrength) * 0.325; $cbranger = floor($cbranged * 1.5) * 0.325; $cbmage = floor($cbmagic * 1.5) * 0.325; return $cbbase + max($cbmelee, $cbranger, $cbmage); } $cb = combatLevel($attack,$defence,$strength,$hitpoints,$prayer,$ranged,$magic,$summoning); $cb = floor($cb); //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ switch ($_GET[sig]) { case '1': header("Content-type: image/png"); $image = imagecreatefrompng("sig1.png"); //imagecolorallocate($image, R, G, B) in HEX values $font_black = imagecolorallocate($image, 2, 1, ; $font_blue = imagecolorallocate($image, 10, 0, 255); $font_yellow = imagecolorallocate($image, 0xFF, 0xFF, 00); $font_grey = imagecolorallocate($image, 0x5A, 0x5A, 0x5A); $font_red = imagecolorallocate($image, 0xA7, 00, 00); //($image, fontsize, rightindent, downindent, data, txtcolour) imagestring($image, 6, 47, 50, $attack, $font_red); imagestring($image, 6, 103, 50, $strength, $font_red); imagestring($image, 6, 159, 50, $defence, $font_red); imagestring($image, 6, 215, 50, $hitpoints, $font_red); imagestring($image, 6, 47, 85, $ranged, $font_red); imagestring($image, 6, 103, 85, $prayer, $font_red); imagestring($image, 6, 159, 85, $magic, $font_red); imagestring($image, 6, 439, 118, $cooking, $font_red); imagestring($image, 6, 327, 50, $woodcutting, $font_red); imagestring($image, 6, 215, 118, $fletching, $font_red); imagestring($image, 6, 383, 118, $fishing, $font_red); imagestring($image, 6, 271, 50, $firemaking, $font_red); imagestring($image, 6, 159, 118, $crafting, $font_red); imagestring($image, 6, 327, 118, $smithing, $font_red); imagestring($image, 6, 271, 118, $mining, $font_red); imagestring($image, 6, 47, 118, $herblore, $font_red); imagestring($image, 6, 215, 85, $agility, $font_red); imagestring($image, 6, 103, 118, $thieving, $font_red); imagestring($image, 6, 271, 85, $slayer, $font_red); imagestring($image, 6, 383, 85, $farming, $font_red); imagestring($image, 6, 383, 50, $runecraft, $font_red); imagestring($image, 6, 439, 50, $construction, $font_red); imagestring($image, 6, 439, 85, $summoning, $font_red); imagestring($image, 6, 327, 85, $hunter, $font_red); imagestring($image, 5, 200, 10, $username, $font_red); imagestring($image, 6, 100, 154, "total:" .$totall, $font_red); imagestring($image, 5, 280, 154, "Swen-Maker", $font_red); imagestring($image, 5, 237, 154, $cb, $font_red); imagepng($image); imagedestroy($image); break; case '2': header("Content-type: image/png"); $image = imagecreatefrompng("sig2.png"); //imagecolorallocate($image, R, G, B) in HEX values $font_black = imagecolorallocate($image, 2, 1, ; $font_blue = imagecolorallocate($image, 10, 0, ; $font_red = imagecolorallocate($image, 0xA7, 00, 00); $font_white = imagecolorallocate($image, 255, 255, 255); //($image, fontsize, rightindent, downindent, data, txtcolour) //rij 4 imagestring($image, 4, 50, 10, $username, $font_white); imagestring($image, 4, 287, 108, "test", $font_white); imagepng($image); imagedestroy($image); break; default: header("Content-type: image/png"); $image = imagecreatefrompng("sig.png"); //imagecolorallocate($image, R, G, B) in HEX values $font_black = imagecolorallocate($image, 2, 1, ; $font_blue = imagecolorallocate($image, 10, 0, ; $font_red = imagecolorallocate($image, 0xA7, 00, 00); //($image, fontsize, rightindent, downindent, data, txtcolour) imagestring($image, 6, 34, 12, $attack, $font_blue); imagestring($image, 6, 413, 45, $hunter, $font_blue); imagestring($image, 4, 83, 119, $username, $font_red); imagestring($image, 5, 88, 45, $agility, $font_blue); imagestring($image, 5, 83, 103, $totall, $font_blue); imagestring($image, 5, 34, 45, $hitpoints, $font_blue); imagepng($image); imagedestroy($image); break; } //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- } } ?> And this is what I made of it <?php if($_GET["name"]) { $username = str_replace(array("_", "-", "|", "+"), " ", $username); $username = ucwords(strtolower($username)); switch ($_GET[sig]) { case '1': header("Content-type: image/png"); $image = imagecreatefrompng("sig1.png"); //imagecolorallocate($image, R, G, B) in HEX values $font_black = imagecolorallocate($image, 2, 1, ; $font_blue = imagecolorallocate($image, 10, 0, 255); $font_yellow = imagecolorallocate($image, 0xFF, 0xFF, 00); $font_grey = imagecolorallocate($image, 0x5A, 0x5A, 0x5A); $font_red = imagecolorallocate($image, 0xA7, 00, 00); imagestring($image, 5, 200, 10, $username, $font_red); imagestring($image, 5, 280, 154, "Swen-Maker", $font_red); imagepng($image); imagedestroy($image); break; case '2': header("Content-type: image/png"); $image = imagecreatefrompng("sig2.png"); //imagecolorallocate($image, R, G, B) in HEX values $font_black = imagecolorallocate($image, 2, 1, ; $font_blue = imagecolorallocate($image, 10, 0, ; $font_red = imagecolorallocate($image, 0xA7, 00, 00); $font_white = imagecolorallocate($image, 255, 255, 255); //($image, fontsize, rightindent, downindent, data, txtcolour) //rij 4 imagestring($image, 4, 50, 10, $username, $font_white); imagestring($image, 4, 287, 108, "test", $font_white); imagepng($image); imagedestroy($image); break; default: header("Content-type: image/png"); $image = imagecreatefrompng("sig.png"); //imagecolorallocate($image, R, G, B) in HEX values $font_black = imagecolorallocate($image, 2, 1, ; $font_blue = imagecolorallocate($image, 10, 0, ; $font_red = imagecolorallocate($image, 0xA7, 00, 00); //($image, fontsize, rightindent, downindent, data, txtcolour) imagestring($image, 4, 83, 119, $username, $font_red); imagepng($image); imagedestroy($image); break; } else { echo "An error occured"; } ?> As you can see I only removed some stuff (I'm a REAL php newb) Can anyone help me fix this problem? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/171955-need-help-on-dynamic-signature-script/ Share on other sites More sharing options...
Asheeown Posted August 26, 2009 Share Posted August 26, 2009 $urldata = get_page("http://hiscore.runescape.com/index_lite.ws?player=".$username); All data for the user is being pulled from here. Obviously the high score list... If the user doesn't exist on the list and there isn't another page in which the data can be pulled from this cannot be accomplished. Quote Link to comment https://forums.phpfreaks.com/topic/171955-need-help-on-dynamic-signature-script/#findComment-906832 Share on other sites More sharing options...
Swenn Posted August 26, 2009 Author Share Posted August 26, 2009 $urldata = get_page("http://hiscore.runescape.com/index_lite.ws?player=".$username); All data for the user is being pulled from here. Obviously the high score list... If the user doesn't exist on the list and there isn't another page in which the data can be pulled from this cannot be accomplished. When I remove that line the script stops working and shows a blank page. Quote Link to comment https://forums.phpfreaks.com/topic/171955-need-help-on-dynamic-signature-script/#findComment-906834 Share on other sites More sharing options...
Asheeown Posted August 26, 2009 Share Posted August 26, 2009 That's exactly what I just said....... ALL information is being pulled there and without it the script cannot function. That is, where it pulls from the high score list also. As I said if there is no other place to get the user's information you cannot use this script. Quote Link to comment https://forums.phpfreaks.com/topic/171955-need-help-on-dynamic-signature-script/#findComment-906838 Share on other sites More sharing options...
Swenn Posted August 26, 2009 Author Share Posted August 26, 2009 That's exactly what I just said....... ALL information is being pulled there and without it the script cannot function. That is, where it pulls from the high score list also. As I said if there is no other place to get the user's information you cannot use this script. There must be a way to just edit it out right? I don't even need the script to get the skills from the highscores, I only want it to show the username one fills in on the main page. Quote Link to comment https://forums.phpfreaks.com/topic/171955-need-help-on-dynamic-signature-script/#findComment-906849 Share on other sites More sharing options...
Asheeown Posted August 26, 2009 Share Posted August 26, 2009 <?php if(empty($_GET["name"]) || !Isset($_GET["name"])) { echo "Please enter a username."; } else { $username = $_GET["name"]; switch ($_GET[sig]) { case '1': header("Content-type: image/png"); $image = imagecreatefrompng("sig1.png"); //imagecolorallocate($image, R, G, B) in HEX values $font_black = imagecolorallocate($image, 2, 1, ; $font_blue = imagecolorallocate($image, 10, 0, 255); $font_yellow = imagecolorallocate($image, 0xFF, 0xFF, 00); $font_grey = imagecolorallocate($image, 0x5A, 0x5A, 0x5A); $font_red = imagecolorallocate($image, 0xA7, 00, 00); imagestring($image, 5, 200, 10, $username, $font_red); imagepng($image); imagedestroy($image); break; case '2': header("Content-type: image/png"); $image = imagecreatefrompng("sig2.png"); //imagecolorallocate($image, R, G, B) in HEX values $font_black = imagecolorallocate($image, 2, 1, ; $font_blue = imagecolorallocate($image, 10, 0, ; $font_red = imagecolorallocate($image, 0xA7, 00, 00); $font_white = imagecolorallocate($image, 255, 255, 255); imagestring($image, 4, 50, 10, $username, $font_white); imagestring($image, 4, 287, 108, "test", $font_white); imagepng($image); imagedestroy($image); break; default: header("Content-type: image/png"); $image = imagecreatefrompng("sig.png"); //imagecolorallocate($image, R, G, B) in HEX values $font_black = imagecolorallocate($image, 2, 1, ; $font_blue = imagecolorallocate($image, 10, 0, ; $font_red = imagecolorallocate($image, 0xA7, 00, 00); imagestring($image, 4, 50, 10, $username, $font_white); imagestring($image, 4, 287, 108, "test", $font_white); imagepng($image); imagedestroy($image); break; } } ?> That works for me, you MUST have the images sig.png sig1.png and sig2.png, depending on which one you go for. sigmaker.php?name=Test - Uses sig.png sigmaker.php?name=Test&sig=1 - Uses sig1.png sigmaker.php?name=Test&sig=2 - Uses sig2.png EDIT: forgot the username definition for the default sig Quote Link to comment https://forums.phpfreaks.com/topic/171955-need-help-on-dynamic-signature-script/#findComment-906859 Share on other sites More sharing options...
Swenn Posted August 26, 2009 Author Share Posted August 26, 2009 <?php if(empty($_GET["name"]) || !Isset($_GET["name"])) { echo "Please enter a username."; } else { $username = $_GET["name"]; switch ($_GET[sig]) { case '1': header("Content-type: image/png"); $image = imagecreatefrompng("sig1.png"); //imagecolorallocate($image, R, G, B) in HEX values $font_black = imagecolorallocate($image, 2, 1, ; $font_blue = imagecolorallocate($image, 10, 0, 255); $font_yellow = imagecolorallocate($image, 0xFF, 0xFF, 00); $font_grey = imagecolorallocate($image, 0x5A, 0x5A, 0x5A); $font_red = imagecolorallocate($image, 0xA7, 00, 00); imagestring($image, 5, 200, 10, $username, $font_red); imagepng($image); imagedestroy($image); break; case '2': header("Content-type: image/png"); $image = imagecreatefrompng("sig2.png"); //imagecolorallocate($image, R, G, B) in HEX values $font_black = imagecolorallocate($image, 2, 1, ; $font_blue = imagecolorallocate($image, 10, 0, ; $font_red = imagecolorallocate($image, 0xA7, 00, 00); $font_white = imagecolorallocate($image, 255, 255, 255); imagestring($image, 4, 50, 10, $username, $font_white); imagestring($image, 4, 287, 108, "test", $font_white); imagepng($image); imagedestroy($image); break; default: header("Content-type: image/png"); $image = imagecreatefrompng("sig.png"); //imagecolorallocate($image, R, G, B) in HEX values $font_black = imagecolorallocate($image, 2, 1, ; $font_blue = imagecolorallocate($image, 10, 0, ; $font_red = imagecolorallocate($image, 0xA7, 00, 00); imagestring($image, 4, 50, 10, $username, $font_white); imagestring($image, 4, 287, 108, "test", $font_white); imagepng($image); imagedestroy($image); break; } } ?> That works for me, you MUST have the images sig.png sig1.png and sig2.png, depending on which one you go for. sigmaker.php?name=Test - Uses sig.png sigmaker.php?name=Test&sig=1 - Uses sig1.png sigmaker.php?name=Test&sig=2 - Uses sig2.png EDIT: forgot the username definition for the default sig Thank you ! This was just what I needed, do you by any chance know how to get the extention of the link to be .png? Most formus don't accept dynamic pages as signatures Quote Link to comment https://forums.phpfreaks.com/topic/171955-need-help-on-dynamic-signature-script/#findComment-906863 Share on other sites More sharing options...
Asheeown Posted August 26, 2009 Share Posted August 26, 2009 To my knowledge I don't think that's possible, to make the link a .png, that's just me of course. You can save the image but with multiple people using it, it may add up to a lot of images. Quote Link to comment https://forums.phpfreaks.com/topic/171955-need-help-on-dynamic-signature-script/#findComment-906869 Share on other sites More sharing options...
Swenn Posted August 26, 2009 Author Share Posted August 26, 2009 To my knowledge I don't think that's possible, to make the link a .png, that's just me of course. You can save the image but with multiple people using it, it may add up to a lot of images. Never mind I already figured it out, for those who want to know: Create a .txt file, open it and paste the following code inside: RewriteEngine On RewriteRule (.+)/sig1.png sig.php?sig=1&name=$1 save it as htaccess.txt Now upload it to the folder you have your signature creator in. (MAKE SURE THIS FOLDER DOESN'T HAVE A .HTACCESS FILE!) rename htaccess.txt to .HTACCESS Now your signature link will be something like "/signature_creator/NAMEHERE/sig1.png" Quote Link to comment https://forums.phpfreaks.com/topic/171955-need-help-on-dynamic-signature-script/#findComment-906880 Share on other sites More sharing options...
Swenn Posted August 26, 2009 Author Share Posted August 26, 2009 I have another question related to this topic. I want the text to be centered on a spot so it fits the image. //($image, fontsize, rightindent, downindent, data, txtcolour) imagestring($image, 5, 255, 9, $username, $font_black); This is the current code, I want the text to be centered on the spot "255, 9" so when I enter a word longer/sorter than the previous one it's still aligned in the center. Exmaple: SampleText Sample The words are both centered, even though the word "Sample" is shorter than "Sample Text" Quote Link to comment https://forums.phpfreaks.com/topic/171955-need-help-on-dynamic-signature-script/#findComment-906955 Share on other sites More sharing options...
Swenn Posted August 27, 2009 Author Share Posted August 27, 2009 I also need to know how to load a new font into the signature, the current one is really ugly :-\ If someone could tell me how to change the font, or even load a new font into the signature, then that would be great! Quote Link to comment https://forums.phpfreaks.com/topic/171955-need-help-on-dynamic-signature-script/#findComment-907574 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.