can you setup a php site like this:

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
abcdabcd
Forum Newbie
Posts: 9
Joined: Tue Jan 27, 2009 11:28 pm

can you setup a php site like this:

Post by abcdabcd »

I have a php file in a folder with a script like this:

Code: Select all

<?php
if($_SERVER['HTTP_REFERER'] != "")
{
$random = rand(0, 2);
$aff_array = array("http://www.website1.com",
                  "http://website2.com",
                  "http:/website3.com");
header("Location: ".$aff_array[rand(0,2)]);
exit();
}
?> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
Basically if there is a referer (visitor came from another website) then they are redirected randomly to 1 of 3 of my other sites above website1, website2, or website3. If they don't have a referer then they are not redirected and stay on the same page (reason for the html code below the php script).

What I'm wondering is when the visitor is redirected to website1, website2, or website3. Is it possible to have the same type of script as above but, in reverse? If the visitor has a referer they stay on the same page and if they don't have a referer then they are redirected to another different webpage? say for example website4.com ?


Thanks
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: can you setup a php site like this:

Post by requinix »

Uh, yeah.

Code: Select all

if($_SERVER['HTTP_REFERER'] != "")
What's the opposite of !=?

If you're trying to do load balancing then you're doing it wrong.
Post Reply