Advertisement
Guest User

Untitled

a guest
Mar 28th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. <?
  2.  
  3.  
  4.  
  5. function formatTime($time){
  6. $time_seconds = $time / 1000;
  7. $time_minutes = $time_seconds / 60;
  8. $time_hours = $time_minutes / 60;
  9. $time_days = floor($time_hours / 24);
  10. $seconds = $time_seconds % 60;
  11. $minutes = $time_minutes % 60;
  12. $hours = $time_hours % 24;
  13.  
  14. $days = floor($time_days % 365);
  15. $years = floor($time_days / 365);
  16.  
  17. return $years . "y " . $days . "d " .$hours . "h " . $minutes . "m ";
  18. }
  19.  
  20.  
  21. $username=""; //Your MySQL Username.
  22. $password=""; // Your MySQL Pass.
  23. $database=""; // Your MySQL database.
  24. $host=""; // Your MySQL host. This is "localhost" or the IP specified by your hosting company.
  25.  
  26.  
  27.  
  28. $player_name=$_GET['player_name']; // This gets the player his name from the previous page.
  29.  
  30.  
  31. mysql_connect($host,$username,$password); // Connection to the database.
  32. @mysql_select_db($database) or die( "Unable to select database. Be sure the databasename exists and online is."); //Selection of the database. If it can't read the database, it'll give an error.
  33.  
  34.  
  35. /* To protect MySQL injection. */
  36. $player_name = stripslashes($player_name);
  37. $player_name = mysql_real_escape_string($player_name);
  38. /* */
  39.  
  40.  
  41.  
  42. if($player_name == "ALL"){ // If you want to sum all of your users data, like I have in my signature, you need this.
  43.  
  44. $query="SELECT SUM(timeran) as timesum FROM Data";
  45. $result=mysql_query($query);
  46. $Timeran1= mysql_fetch_assoc($result);
  47. $Timeran = $Timeran1[timesum];
  48.  
  49.  
  50. $query="SELECT SUM(expgained) as expsum FROM Data";
  51. $result=mysql_query($query);
  52. $ExpGained1= mysql_fetch_assoc($result);
  53. $ExpGained = $ExpGained1[expsum];
  54.  
  55.  
  56. // Now for the creation of the image.
  57.  
  58.  
  59.  
  60. header('Content-Type: image/png;');
  61. // Your image must be in the same directory as your PHP Scripts for it to work, otherwise you will need to include a path
  62. $im = @imagecreatefrompng('YOUR_IMAGE.png') or die("Cannot find image, check naming and file location");
  63.  
  64.  
  65.  
  66. $text_color = imagecolorallocate($im, 255,255,100); // RED, GREEN, BLUE , you can goto http://colorpicker.com to pick a nice colour if you wish.
  67.  
  68. $text_username = "ALL"; // This gets the information about player name to be showed in the picture.
  69. $text_timeran = formatTime($Timeran); // Same as above ^^
  70. $text_expgained = number_format($ExpGained);
  71.  
  72.  
  73. $font = 'Calibri.ttf'; //Upload your custum font to the directory where this file is placed if you wish to customise it.
  74.  
  75. // 18 is the font size, 0 is the angel of the text, 165 is the x coordinate on your image, and 132 is the Y coordinate on your image.
  76. imagettftext($im, 18, 0, 165, 132, $text_color, $font, 'ALL');
  77. imagettftext($im, 12, 0, 300, 93, $text_color, $font, $text_timeran);
  78. imagettftext($im, 14, 0, 130, 93, $text_color, $font, $text_expgained);
  79. imagepng($im);
  80. imagedestroy($im);
  81. return;
  82. }
  83.  
  84. // Below is the code for regular players, it will not SUM
  85.  
  86. $query="SELECT * FROM Data WHERE Username='$player_name'"; // Gets all the information about the player.
  87.  
  88. $result=mysql_query($query);
  89. $i=mysql_num_rows($result); // Here we are counting how many rows this result gives us.
  90.  
  91.  
  92. if ($i == 1) // If the user has been correct, then it'll give us 1 row. If its 1 row, then it'll proceed with the code.
  93. {
  94.  
  95.  
  96. $Username=mysql_result($result,0,"Username");
  97. $Timeran=mysql_result($result,0,"timeran");
  98. $ExpGained=mysql_result($result,0,"expgained");
  99.  
  100. // Creating of the .png image.
  101.  
  102.  
  103.  
  104. header('Content-Type: image/png;');
  105.  
  106.  
  107.  
  108. header('Content-Type: image/png;');
  109. // Your image must be in the same directory as your PHP Scripts for it to work, otherwise you will need to include a path
  110. $im = @imagecreatefrompng('YOUR_IMAGE.png') or die("Cannot find image, check naming and file location");
  111.  
  112. $text_color = imagecolorallocate($im, 255,255,100); // RED, GREEN, BLUE , you can goto http://colorpicker.com to pick a nice colour if you wish.
  113. $text_username = "$Username"; // This gets the information about player name to be showed in the picture. // This gets the information about player name to be showed in the picture.
  114. $text_timeran = formatTime($Timeran); // Same as above ^^
  115. $text_expgained = number_format($ExpGained);
  116.  
  117. $font = 'Calibri.ttf'; //Upload your custum font to the directory where this file is placed. Then change the name here.
  118.  
  119. // 18 is the font size, 0 is the angel of the text, 165 is the x coordinate on your image, and 132 is the Y coordinate on your image.
  120. imagettftext($im, 12, 0, 138, 130, $text_color, $font, $text_username);
  121. imagettftext($im, 12, 0, 300, 93, $text_color, $font, $text_timeran);
  122. imagettftext($im, 14, 0, 138, 93, $text_color, $font, $text_expgained);
  123.  
  124.  
  125.  
  126. imagepng($im);
  127. imagedestroy($im);
  128.  
  129. } else echo('Username is not in our database. Please try again.'); // If the username doesn't exist (so the row is 0) then it'll give en error.
  130.  
  131. mysql_close();
  132.  
  133. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement