Jump to content

Download data if it's been more than a specified amount of time


sp@rky13

Recommended Posts

Ok so what I want to do is that if a person accesses a php page and it has been more than one hour since the last download, then it should download the data. How can I do this?

 

This is my download code currently for one of my 3 pieces of data:

 

<?php
ini_set(memory_limit,"80M");
$current_world = 28;

$connection = mysql_connect("localhost","","");
if (!$connection){
die("Could not connect: ". mysql_error());
}
$db_database = "wwwspark_tribalwars";
$db_select = mysql_select_db($db_database); 
if(!$db_select){
die("Could not select the database: <br>". mysql_error());
}


$delete = mysql_query("DELETE FROM villages_en".$current_world." WHERE 1=1");
if(!$delete){
die("Could not delete previous database---world28_villages". mysql_error());
}

$lines = gzfile('http://en'.$current_world.'.tribalwars.net/map/village.txt.gz');
if(!is_array($lines)) die("File could not be opened");
foreach($lines as $line) {
	list($id, $name, $x, $y, $player, $points, $rank) = explode(',', $line);
	$name = urldecode($name);

	$name = addslashes($name);
	$query = mysql_query("INSERT INTO villages_en".$current_world." SET id='$id', name='$name', x='$x', y='$y',
	player='$player', points='$points', rank='$rank'");
	if(!$query){
		die("Could not insert the database: <br>". mysql_error());
	}
}

mysql_close($connection);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.