luke777 Posted December 23, 2007 Share Posted December 23, 2007 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 !!! Thanks Luke. Quote Link to comment Share on other sites More sharing options...
papaface Posted December 23, 2007 Share Posted December 23, 2007 Use a cron job. Quote Link to comment Share on other sites More sharing options...
luke777 Posted December 23, 2007 Author Share Posted December 23, 2007 Could you expand a little more on this.... iv never used a con job before on my server... and dont fully understand what it is. Thanks Luke. Quote Link to comment Share on other sites More sharing options...
papaface Posted December 23, 2007 Share Posted December 23, 2007 yeah np: http://www.google.co.uk/search?q=what+is+a+cron+job&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a and: http://www.google.co.uk/search?hl=en&safe=off&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=tb&q=define%3Acron+job&btnG=Search&meta= lol Quote Link to comment Share on other sites More sharing options...
luke777 Posted December 23, 2007 Author Share Posted December 23, 2007 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. Quote Link to comment Share on other sites More sharing options...
shocker-z Posted December 23, 2007 Share Posted December 23, 2007 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 Quote Link to comment Share on other sites More sharing options...
papaface Posted December 23, 2007 Share Posted December 23, 2007 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. Quote Link to comment Share on other sites More sharing options...
luke777 Posted December 24, 2007 Author Share Posted December 24, 2007 I dont know much php at the moment would you mind implementing this for me ? Would really appreciate it if you could Also, will this still send the specified ammount of hits out to each site? (i need it to) Thanks Luke. Quote Link to comment Share on other sites More sharing options...
papaface Posted December 24, 2007 Share Posted December 24, 2007 I won't do it for you. But this is the code you need I think: $count = count($urls) - 1; $rand = rand(0,$count); $url=explode('||',$urls[$rand]); $url[0]// URL part $url[1]// amount of hits Quote Link to comment Share on other sites More sharing options...
luke777 Posted December 24, 2007 Author Share Posted December 24, 2007 ok great but i dont know where to put it ... :-\ Quote Link to comment Share on other sites More sharing options...
luke777 Posted December 25, 2007 Author Share Posted December 25, 2007 ??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.