Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
can you setup a php site like this:
Old 03-02-2009, 02:34 AM can you setup a php site like this:
Novice Talker

Posts: 14
Trades: 0
I have a php file in a folder with a script like this:

PHP Code:
<?php
if($_SERVER['HTTP_REFERER'] != "")
{
$random rand(02);
$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
abcdabcd is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-03-2009, 02:41 PM Re: can you setup a php site like this:
Jaryth000's Avatar
Skilled Talker

Posts: 59
Name: Jaryth
Location: Canada
Trades: 0
First off, not sure why you set the $random, when you end up just using the formula later on...

At any rate. So, you have a page set up, so that when you go to it with no referrer, it shows the page as normal. But if you visit the page with a referrer, it will automatically redirect you to another page... Correct?


PHP Code:
<?php
if($_SERVER['HTTP_REFERER'] = "")
{
$aff_array = array("http://www.website1.com",
                  
"http://website2.com",
                  
"http:/website3.com");
header("Location: ".$aff_array[rand(0,2)]);
exit();
}
?>
With the above code, if there was NO Referrer it would direct them to another page. However if there was a referer it would show the HTML after the PHP script. Is that what you where looking for? (Note all I really did was change the NOT EQUAL to (!=) to EQUAL (=).)
__________________

Please login or register to view this content. Registration is FREE
My personal website
-Jaryth (UID590)
Jaryth000 is offline
Reply With Quote
View Public Profile Visit Jaryth000's homepage!
 
Old 03-03-2009, 05:55 PM Re: can you setup a php site like this:
Novice Talker

Posts: 14
Trades: 0
Thanks for your reply.

"So, you have a page set up, so that when you go to it with no referrer, it shows the page as normal. But if you visit the page with a referrer, it will automatically redirect you to another page... Correct?"

Yes, that is how the code works now. It already works fine like that.

Although what I'm wanting to know is, when the user is redirected (if they have a referer) just like how it works now. When they get to the next page (the redirected page) is it possible to setup the same script but, in an opposite manner. So, on the next page (the redirected) page there is a code that will keep them on this page if there IS a referer and if there is no referer it will redirect them to another webpage.

So, I'm wanting to setup the same type of code on the redirected page as on the 1st page but, in reverse.. does that make sense?




Quote:
Originally Posted by Jaryth000 View Post
First off, not sure why you set the $random, when you end up just using the formula later on...

At any rate. So, you have a page set up, so that when you go to it with no referrer, it shows the page as normal. But if you visit the page with a referrer, it will automatically redirect you to another page... Correct?


PHP Code:
<?php
if($_SERVER['HTTP_REFERER'] = "")
{
$aff_array = array("http://www.website1.com",
                  
"http://website2.com",
                  
"http:/website3.com");
header("Location: ".$aff_array[rand(0,2)]);
exit();
}
?>
With the above code, if there was NO Referrer it would direct them to another page. However if there was a referer it would show the HTML after the PHP script. Is that what you where looking for? (Note all I really did was change the NOT EQUAL to (!=) to EQUAL (=).)
abcdabcd is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to can you setup a php site like this:
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12231 seconds with 12 queries