Hi All I am looking for an code or script that able me to redirect my visitors per number of visits to three sites For example i have 300 visitor per day, i want to redirect 100 of them to Google.com and 100 of them to Yahoo.com and 100 of them to MSN.com Automatically Please if there is any code or script can do that? I really need this.. Thanks
$sites = array( 'http://www.google.com', 'http://www.yahoo.com', 'http://www.msn.com'); header('Location: '.$sites[rand(0,count($sites)-1]); PHP: This will randomly pick one and redirect. with the laws of averages, it should even out
Hi Here is a simple script. <?php $count = file_get_contents("counter.txt"); // has the date and the count something like count:date eg. 223:23_02_2008 $count = split(":",$count); $date = $count[0]; $curr_date = date("d_m_Y"); if($curr_date != $date) { $count = 0; $date = $curr_date; } file_put_contents("counter.txt",$count.":".$date); if($count < 100) { header("location:url1");// For hits less than 100; } elseif(($count < 200) && ($count > 100)) { header("location:url2"); // For hits more than 100; } elseif(($count < 300) && ($count > 200)) { header("location:url3"); // For hits more than 200; } else { header("location: url4"); // For hits more than 300; } ?> PHP: You will need php 5 for this. (file_get_contents) works in PHP 5 only. Hope this helps. Thanks imphpguru
plus theres the compatability functions available at php.net for people on versions before that....but you are right, it should be 5 only now
include and ob_start and ob_getclean for example. or fread and filesize. But PHP 4 is no longer developed.
Hi, Yeah! PHP 4 is bye bye now. Just wanted to make sure you are in the right version... you can do it using php 4 also by fopen and fread. Thanks imphpguru
I think he was actually on about file_put_contents, that's used and is PHP 5+. Uber easy to port most of it's features back to 4 though
imphpguru Thanks your code is work.. JAY6390 your code is not work, I have created a new php page and i have placed the code that you send me there: <?php $sites = array( 'http://www.google.com', 'http://www.yahoo.com', 'http://www.msn.com'); header('Location: '.$sites[rand(0,count($sites)-1]); ?> But i just see a blank page, for example when i open this page i see an white page with no action (a blank page).. Can anybody help? Is there is something wrong with the code? thanks