nicobach1 Posted December 29, 2009 Share Posted December 29, 2009 how can i have a link re-direct after it has been clicked a certain amount of times> Could i use php for this, and if yes, please explain how, since im a newb at php. thanks in advance! Link to comment https://forums.phpfreaks.com/topic/186612-page-redirect-after-x-amount-of-clicks/ Share on other sites More sharing options...
p2grace Posted December 29, 2009 Share Posted December 29, 2009 There are a couple ways of achieving this. One method would be that all links are redirect links, and you use session variables to determine number of clicks. Then in the redirect, if it shouldn't redirect again (based off of session variable check) just send to initial link, otherwise redirect to new link. There isn't a straight simple answer for this one, some digging and understanding of php methods (and javascript most likely) will be required. Link to comment https://forums.phpfreaks.com/topic/186612-page-redirect-after-x-amount-of-clicks/#findComment-985619 Share on other sites More sharing options...
nicobach1 Posted December 29, 2009 Author Share Posted December 29, 2009 p2grace, I have been searching for some sort of code pretty much all day and i just cant seem to find anything, if you could point me to a site the explains how to do what im looking for i would greatly appreciate it since i really need this done soon! thanks Link to comment https://forums.phpfreaks.com/topic/186612-page-redirect-after-x-amount-of-clicks/#findComment-985621 Share on other sites More sharing options...
Mountain Water Posted December 29, 2009 Share Posted December 29, 2009 There are a couple ways of achieving this. One method would be that all links are redirect links, and you use session variables to determine number of clicks. Then in the redirect, if it shouldn't redirect again (based off of session variable check) just send to initial link, otherwise redirect to new link. There isn't a straight simple answer for this one, some digging and understanding of php methods (and javascript most likely) will be required. Very easy way. Set a cookie then if $_COOK['xxx'] > 5 header(Location: bla bla); Link to comment https://forums.phpfreaks.com/topic/186612-page-redirect-after-x-amount-of-clicks/#findComment-985624 Share on other sites More sharing options...
p2grace Posted December 29, 2009 Share Posted December 29, 2009 There are a couple ways of achieving this. One method would be that all links are redirect links, and you use session variables to determine number of clicks. Then in the redirect, if it shouldn't redirect again (based off of session variable check) just send to initial link, otherwise redirect to new link. There isn't a straight simple answer for this one, some digging and understanding of php methods (and javascript most likely) will be required. Very easy way. Set a cookie then if $_COOK['xxx'] > 5 header(Location: bla bla); This could work, however if a user refreshes their page this will also redirect, and this assumes the content is templatized. You also wouldn't be able to track to which link they are referring from if that data was necessary. Also, I wouldn't recommend using cookies for this, but rather sessions that way you can use multi-dimensional arrays. Link to comment https://forums.phpfreaks.com/topic/186612-page-redirect-after-x-amount-of-clicks/#findComment-985626 Share on other sites More sharing options...
nicobach1 Posted December 29, 2009 Author Share Posted December 29, 2009 if i use cookies wouldn't that be for each visitor and not for everyone visiting my site? Would i be able to use a text file or database that would track how often a certain link has been clicked, and if it has been clicked more than five times, then redirect to a certain page? and if that is possible, again i would need help in order to accomplish this since my knowledge of php and sql is very small. Link to comment https://forums.phpfreaks.com/topic/186612-page-redirect-after-x-amount-of-clicks/#findComment-985633 Share on other sites More sharing options...
p2grace Posted December 29, 2009 Share Posted December 29, 2009 You would use cookies if you want the redirects to be remembered throughout each visit. As far as tracking goes, a database would be the best option. Like I said before, you'll need to do some research and googling to learn the information you need. The link below demonstrates how to connect to a mysql database (assuming you have one created). http://www.siteground.com/tutorials/php-mysql/php_mysql_connection.htm Link to comment https://forums.phpfreaks.com/topic/186612-page-redirect-after-x-amount-of-clicks/#findComment-985634 Share on other sites More sharing options...
nicobach1 Posted December 29, 2009 Author Share Posted December 29, 2009 would you be able to provide me with the php code on how it would track how many times a link has been clicked, since i really don't know where to begin. I think that i would use the header("Location: location.php") code to specifiy what page to redirect to after 5 clicks, but im not even sure about that. Like i said, i know very very little about php. I really appreciative any help you can offer. thanks Link to comment https://forums.phpfreaks.com/topic/186612-page-redirect-after-x-amount-of-clicks/#findComment-985646 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.