Forum Moderators: coopster

Message Too Old, No Replies

URL on my site to redirects to different address on every access

         

Darrel1

9:04 am on Apr 25, 2011 (gmt 0)

10+ Year Member



Hello!
I was wondering how can I do the following:
Get a URL/Page on my site that redirects to a different URL after every access to it, according to a predetermined list of URL's

For example, I'll enter a text file with a list of 5 websites, then I'll surf to the URL on my site which will redirect me to the first website on the list. When I surf this URL again it will redirect me to the second website on the list, and so forth.

How can I do it?

Thank you!

nofork

4:06 pm on Apr 26, 2011 (gmt 0)

10+ Year Member



Something like the below?

Probably needs a bit more time on it to make it clearer.
<?php
if (isset($_COOKIE["urlnumber"])){
$valueurl=$_COOKIE["urlnumber"]+1;
if ($valueurl==5){
$valueurl=0;
}
} else {
$valueurl=0;
}
setcookie("urlnumber", $valueurl);
$sites = array("http://www.google.co.uk", "http://www.yahoo.com", "www.apple.com", "www.bing.com", "http://www.sitepoint.com/");
$url_redirect=$sites[$valueurl];
header('Location: '.$url_redirect);
?>


Hope that helps,
Matt

[edited by: eelixduppy at 4:19 pm (utc) on Apr 26, 2011]
[edit reason] no URL signatures, please [/edit]

Darrel1

6:57 pm on Apr 26, 2011 (gmt 0)

10+ Year Member



It's working!
Matt, you just made my day! Thank you!

nofork

8:12 am on Apr 27, 2011 (gmt 0)

10+ Year Member



No problem Darrel glad I could help

Darrel1

9:49 am on May 8, 2011 (gmt 0)

10+ Year Member



Hello again!

So I tried it one more time and I noticed it does work but a bit different then I expected..
Currently it redirects according to browser/user, so when 2 different people surf from different browsers both get to the 1st URL.
I expected the 1st person to get to the first URL and the 2nd person to the second URL, and so on (so it will redirect base on "page request"/"page load", no mater the browser).

Is it possible?

g1smd

4:15 pm on May 8, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You could if you stored the counter data in a database or in a text file on the webserver so it was available between sessions and for different users.

nofork

8:00 am on May 9, 2011 (gmt 0)

10+ Year Member



Agreed with g1smd, the best way to do it would be to save to a database or a text. file on your server.

Does it have to be in sequence? You could have a random page initially then use the cookie to make sure they got the next one in sequence? That would be much easier.

Cheers, Matt