GIDForums  

Go Back   GIDForums > Webmaster Forums > Web Design Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Mar-2009, 04:26
forwardvision forwardvision is offline
New Member
 
Join Date: Aug 2006
Posts: 6
forwardvision is on a distinguished road
Question

Redirecting to Multiple Sites, Each in Turn


Hi Guys,

I wonder if someone can please advise me on how to do this please.

I am a distributor for a company & I want to do some advertising with some fellow colleagues. We all have our own individual websites. The advert will have one web address, which will for each hit redirect to a different website.

So for instance, let's say the web address on the advert is http://www.our-advert.com and there are 4 of us sharing the cost of the ad with our own individual sites:

Fred: http://www.freds-site.com
John: http://www.johns-website.com
Jane: http://www.jane-online.com
Jill: http://www.jill-on-the.net

Now, the first time someone goes onto our-advert.com, it will redirect to Fred's site, the second hit will redirect to John's, the next to Jane's, the next to Jill's and then the next to Fred's and so on and so forth.

How do I do this? I am guessing it will have to be in something like php or javascript? Please can anyone advise me on this?

Thanks,

Jason
  #2  
Old 20-Mar-2009, 05:53
Blake's Avatar
Blake Blake is offline
Regular Member
 
Join Date: Nov 2005
Posts: 330
Blake is a jewel in the roughBlake is a jewel in the roughBlake is a jewel in the rough

Re: Redirecting to Multiple Sites, Each in Turn


You could do something like this:

PHP Code:

<?php

    $sites = Array("http://www.freds-site.com",
                   "http://www.johns-website.com",
                   "http://www.jane-online.com",
                   "http://www.jill-on-the.net");

    $numSites = sizeof($sites);

    $currentSite =  isset($_COOKIE['lastsite']) ?
        ($_COOKIE['lastsite'] + 1) % $numSites :
        rand() % $numSites;
    setCookie('lastsite', $currentSite);
    header("Location: " . $sites[$currentSite]);

?>


It sets a cookie to keep track of the last site visited. If the cookie is not found, it goes to a random site. On each visit, it updates the cookie.

If you want a global counter instead (so that it goes to the next site each time you get a hit from anywhere), you could do this:

PHP Code:

<?php

    $sites = Array("http://www.freds-site.com",
                   "http://www.johns-website.com",
                   "http://www.jane-online.com",
                   "http://www.jill-on-the.net");
    $numSites = sizeof($sites);
    $lastSite = 0;
    if (file_exists("lastsite.txt")) $lastSite = file_get_contents("lastsite.txt");
    $currentSite = ($lastSite + 1) % $numSites;
    $f = fopen("lastsite.txt", "w+");
    fwrite($f, $currentSite);
    fclose($f);
    header("Location: " . $sites[$currentSite]);

?>


This example keeps a text file on the server ("lastsite.txt") which has a number representing the last site visited by anyone. Any time someone goes to your url, the counter in the file is updated, so that the next time someone visits your site, the counter will be updated.
__________________
www.blake-foster.com
 
 

Recent GIDBlogInstall Adobe Flash - Without Administrator Rights by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error C2374 lolp1 C++ Forum 3 25-May-2008 16:40
Reliable & Affordable.. RVSKIN|PHP5|FANTASTICO|CPANEL and much more.. + Coupon!! .amaZe Web Hosting Advertisements & Offers 0 28-Sep-2007 13:33
VPS at ArteryPlanet.Net - Virtuozzo/cPanel/ WHM/Fantastico Multiple Free domain names arteryplanet Web Hosting Advertisements & Offers 0 07-Apr-2006 12:23
Linker errors with multiple file progam nkhambal C Programming Language 2 24-Apr-2005 02:37

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:14.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.