Hi. I have made a simple PHP script to check for banned IPs and redirect the banned ones to a certain URL, then redirect the other non banned IPs to a different URL. What I am now trying to do is make the script be able to randomly redirect the non banned ones to one of 5 or so URLs that I have. For example. I have a number of different affiliate offers for a free credit report and I want to send each non banned IPs to a randomly chosen URL so each affiliate offer will get some traffic and hopefully some sales. Below is the code I have already written. If someone could help show me how to make it do the random URL thing, I would appreciate it. <?php $banned_ip = array(); $banned_ip[] = '204.96.148.3'; $banned_ip[] = '205.162.217.141'; foreach($banned_ip as $banned) { $ip = $_SERVER['REMOTE_ADDR']; if($ip == $banned) { header("location: http://you-are-banned.com"); die();//abort the script on redirect. just in case. } } //if we got this far, their IP is obviously not banned //this is where I would like it to have numerous URLs to randomly send each visitor to one of them header("location: http://www.freecreditreport1.com"); ?> Code (markup):
// after checking banned domains $urls = array(); $urls[0] = "http://www...."; //url goes here $urls[1] = "...."; // url goes here ... $total = count($urls); $url = $urls[rand($total-1)]; header("Location: ".$url); PHP:
do it in the same way with an array add this at the final $affiliates = array("url1", "url2", "etc"); $max = sizeof($affiliates); $random = rand(0, $max); header("location: $affiliates[$random]");