Jump to content

PHP SCRIPT - SENDS HITS OUT


luke777

Recommended Posts

Hi :)

 

At the moment this script works perfect, sends out the number of hits to each site i want it to.... it stores data in a file called stats.omg

 

What I need is... for it to be changed so that hits are not sent out in bulk, i need to spread the traffic out over the the whole day instead of the sites recieving a bulk of traffic at 1 point in the day.

 

Games.php contains:

 

<?php
$urls="http://www.site1.com||6,http://www.site2.com||10,http://www.site3.com||3";
$urls=explode(",",$urls);
$i=0;
foreach($urls as $url){
$url=explode('||',$url);
$sites[$i]['url']=$url[0];
$sites[$i]['hits']=$url[1];
$i++;
}
$omg=file_get_contents('stats.omg');
$handle=fopen('stats.omg','w+');
if(!$omg){
	foreach($sites as $site){
	$stats[]=0;
	}
} else{
$stats=unserialize($omg);
}

for($i=0;$i<=count($sites)-1;$i++){
	if($stats[$i]<$sites[$i]['hits']){
	$stats[$i]++;
	$stats=serialize($stats);
	fwrite($handle,$stats,strlen($stats));
	header("Location: {$sites[$i]['url']}");
	exit;
	}
}
header("location: games.php"); // all hits set, reload and start over
?>

 

If anyone could modify this script for me i would REALLY appreciate it !!!  ;D

 

Thanks Luke.

Link to comment
https://forums.phpfreaks.com/topic/82944-php-script-sends-hits-out/
Share on other sites

So how would setting a time for my server to do somthing make this work :| ???... i dont think a cron job would solve my problem.... mabe you should read over it agen  ;)

 

All that needs to be done is the script made to select a random site to send the hit to.

I dont fully understand what your wanting to do? You wanting to restrict access ot your site, so that only say 5 users can log on in 1 hour?

 

Or are you saying your hit's file is too big and you need to seperate the file into multiple files?

 

 

Regards

Liam

So how would setting a time for my server to do somthing make this work :| ???... i dont think a cron job would solve my problem.... mabe you should read over it agen  ;)

 

All that needs to be done is the script made to select a random site to send the hit to.

Well instead of using a foreach on your $urls, just select one at random.

This will count how many URLS there are.

$count = count($urls) - 1;

This will chose a random key.

$rand = rand(0,$count);
echo $urls[$rand];

That should help you on your way.

 

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.