Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_id("statistics"); //Selects this ID
- session_start(); //Starts a session
- $tier = $_REQUEST['filename'];
- $var_name = $_REQUEST['id'];
- if (isset($_SESSION["CREATION_DATE"])) { //Sets the creation date
- if ($_SESSION["CREATION_DATE"] != date("Y-m-d")) {
- session_destroy(); //If it is a different day it destroys the information
- $_SESSION["CREATION_DATE"] = date("Y-m-d"); //the session variable hold
- } else {
- $_SESSION["CREATION_DATE"] = date("Y-m-d");
- }
- }
- if (!isset($_SESSION[$tier]))
- $_SESSION[$tier] = getData($tier);
- function getData ($new_tier) { //This function downloads the statistics from the official smogon website
- $filename = "http://www.smogon.com/stats/date/moveset/".$new_tier;
- $contents = null;
- $i = 0;
- while ($contents == null) {
- $year = date("Y");
- $month = date("m")-$i;
- if ($month < 10)
- $month = "0".$month;
- $date = $year."-".$month;
- if (intval(get_http_response_code(str_replace("date", $date, $filename))) < 400) {
- $contents = file_get_contents(str_replace("date", $date, $filename));
- } else {
- $contents = null;
- }
- $i++;
- if ($i > 10)
- $contents = "not found!";
- }
- $contents = str_replace("\n", '" + "', $contents); //Replaces \n with ' + ' to concat each line of the text
- $contents = preg_replace('/\s+/', ' ', $contents); //Removes white spaces
- $contents = strtolower($contents); //Makes everything lower case
- return $contents;
- }
- function get_http_response_code($theURL) {
- $headers = get_headers($theURL);
- return substr($headers[0], 9, 3);
- }
- echo "<script>parent.".$var_name.' = "'.$_SESSION[$tier].'"; </script>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement