Yes you got it. $i is needed because we have created two arrays:
Code:
[COLOR=#000000][COLOR=#0000bb][COLOR=White]$referer = array("google.com","yahoo.com","msn.com");
$redirect = array("www.site1.com", "www.site2.com", "www.site3.com");[/COLOR][/COLOR][/COLOR]
$i is a basic counter. So the array items are set up like this:
Code:
$referer[0] = google.com
$referer[1] = yahoo.com
$referer[2] = msn.com
$redirect[0] = www.site1.com
$redirect[1] = www.site2.com
$redirect[2] = www.site3.com
This way we can easily use one variable (
$i) to access both arrays. So here's a little walk through:
Code:
for($i=0;$i<count($referer);$i++)
Set up a counter,
$i will have a starting value of
0,
$i++ means the variable
$i will be incremented by
1 each time through the loop, and the loop ends when
$i equals more that how many items are in our array represented by
count($referer). In this example
count($referer) is equal to
3.
Code:
if(stristr($_SERVER['HTTP_REFERER'], $referer[$i]))
We make a check to see if our referer string is inside the HTTP_REFERER. On the first pass
$referer[$i] equates to
$referer[0] which has a value of
google.com.
stristr will return
FALSE if there is no match, so we only test against a
non-False clause.
Code:
header("Location: " . $redirect[$i]);
For the sake of argument, lets say the previous expression is true,
$redirect[$i] will evaluate to
$redirect[0] which has a value of
www.site1.com. This will end up making the line look like:
header("Location: www.site1.com");
And the user goes on there marry way. Now if we didn't get a match, the whole possess starts over only
$i will be incremented by
1, to a value of
1.
Any more questions feel free to ask.