Jump to content

PHP Bandwith control advice


KingOfHeart

Recommended Posts

I like creating php images, and linking them on other sites. Since I do not own the site I need to make sure I don't use up all their bandwith. So I created a htaccess file to only allow certain hosts to link to my image.

I also created a php script. Is this a good php script for controlling the bandwith for an image?

 

 

function UpdateTable()
{
$tsql="SELECT * FROM Bandwith";
$tresult=mysql_query($tsql);

while($trows=mysql_fetch_array($tresult))
{
	$time = $trows['id'];
	if(date("His") > $time + 500 || date("His") < $time - 500)
		mysql_query("DELETE FROM Bandwith WHERE id='$time'"); 
}
$tresult=mysql_query($tsql);
if(mysql_num_rows($tresult) > 40)//too many views within 5 min so shut down
{
	$Handle = fopen(".htaccess", 'a');
	$Data = chr(10) . "Deny from all";
	fwrite($Handle, $Data); 
}
}

 

I have this line later on in my script.

mysql_query("INSERT INTO Bandwith

(id, ip, host,page) VALUES('$time', '$ip', '$host','$page') ");

 

mysql_query("Update Bandwith SET image = '$image' WHERE id = '$time' AND ip = '$ip'");

 

 

I now question myself on why I separated those two lines, which I think I'll combine. Anyways, is this a good method for controlling bandwith abuse?

Link to comment
https://forums.phpfreaks.com/topic/150816-php-bandwith-control-advice/
Share on other sites

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.