Advertisement
Guest User

Untitled

a guest
Jun 30th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. <?php
  2. //FetchVotes.php (c) by Benni1000 | use only on minecraft-server.eu
  3.  
  4. //Configuration///////////////////////////////////////////
  5. $link = "http://minecraft-server.eu/?go=server&id=xxx"; //Your Server id
  6. $expireTime = 5;                                        //Expire Time in Minutes
  7. $msg = "Votes: ";                                       //Message, you can leave it empty
  8. $file = "votes.vdb";                                    //File name (file will be created)
  9. /////////////////////////////////////////////////////////
  10.  
  11. //functions
  12. function fetchVotes($link) {
  13.   $votes1 = explode("<td colspan=1>",file_get_contents($link));
  14.   $votes2 = explode("</td>",$votes1[1]);
  15.   return $votes2[0];
  16. }
  17.  
  18. function writeVotes($file,$link,$expireTime) {
  19. if(file_exists($file)) {
  20.   unlink($file);
  21. }
  22. $handle = fopen($file,"w");
  23. fwrite($handle,strtotime('+'.$expireTime.' minutes').",".fetchVotes($link)) or die("Critical IO Error!");
  24. fclose($handle);
  25. }
  26.  
  27. //Main
  28. if(!file_exists($file)) {
  29. writeVotes($file,$link,$expireTime);
  30. }
  31. $handle = fopen($file,"r");
  32. $exploded = explode(",",fread($handle, filesize($file)));
  33. $Votes = $exploded[1];
  34. $Date = $exploded[0];
  35. if(strtotime("now") > $Date)  {
  36.   writeVotes($file,$link,$expireTime);
  37.   $handle = fopen($file,"r");
  38.   $exploded = explode(",",fread($handle, filesize($file)));
  39.   echo $msg.$exploded[1];
  40. }
  41. else {
  42. echo $msg.$Votes;
  43. }
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement