Gregghawes Posted March 6, 2009 Share Posted March 6, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/148183-redirect-loop/ Share on other sites More sharing options...
sKunKbad Posted March 6, 2009 Share Posted March 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/148183-redirect-loop/#findComment-777858 Share on other sites More sharing options...
Gregghawes Posted March 6, 2009 Author Share Posted March 6, 2009 Hi thanks for your reply, I already know a bit about mysql, I use dreamweaver so my coding knowledge is pretty much 0, I have a database with the websites but how would i actually code the php side of things, i can so the connection stuff fine. Quote Link to comment https://forums.phpfreaks.com/topic/148183-redirect-loop/#findComment-777869 Share on other sites More sharing options...
sKunKbad Posted March 6, 2009 Share Posted March 6, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/148183-redirect-loop/#findComment-777941 Share on other sites More sharing options...
Gregghawes Posted March 6, 2009 Author Share Posted March 6, 2009 thats awesome thanks alot, at least I got something to go on now. Cheers for that Quote Link to comment https://forums.phpfreaks.com/topic/148183-redirect-loop/#findComment-777948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.