Jump to content

Redirect Loop


Gregghawes

Recommended Posts

Hi,

 

I hope someone can help me. I have a series of websites that i want to advertise with adwords. What i would like to do is a redirect loop, where the 1st person that clicks on the ad would be directed to the 1st site in the loop, the next person that clicks would goto the next site etc. Once the last site in the loop has been clicked I would like the loop to start over again.

 

Can anyone point me in the right direction? I'm quite new to php so i'm not even sure what kinda loop to use. I know I have to use the header function.

 

Thanks In advance.

 

Gregg

Link to comment
https://forums.phpfreaks.com/topic/148183-redirect-loop/
Share on other sites

Probably the easiest thing to do would be to set up a mysql database of the URLs to link to, and then add a counter to the database. When somebody gets redirected, simply update the counter +1 unless it is at the last number (determined by the number of links). If that is the case, update the counter to zero, so it starts all over again.

 

So, you need to learn some BASIC MySQL, but it shouldn't be hard at all. Just search for some tutorials on MySQL and PHP.

Link to comment
https://forums.phpfreaks.com/topic/148183-redirect-loop/#findComment-777858
Share on other sites

Unless you have  a huge number of links, you might just store the links in an associative array. Then query the database with a simple query:

 

$q=mysql_query("SELECT count FROM counter");

$row = mysql_fetch_array($q,MYSQL_ASSOC);

// so you can use $row['count'] as the number to get the link you want

 

$arr = array("1"=>"http://www.whatever.com","2"=>"http://www.whatever2.com");

 

echo $arr["$row['count']"];

 

//I can't do all the work for you, you'll have to figure out if I made errors

if ($row['count'] == 2){ // 2 because there are only two elements in the array above, and they are numbered 1 and 2.

mysql_query("UPDATE counter SET count =  1");

}else{

mysql_query("UPDATE counter SET count =  ({$row['count']} + 1)");

}

 

//This should steer you in the right direction

Link to comment
https://forums.phpfreaks.com/topic/148183-redirect-loop/#findComment-777941
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.