dhorn Posted July 20, 2009 Share Posted July 20, 2009 I am helping develop for a website that wants a pop-in (displays a hidden div) to occur every certain number of pageviews or on a special time limit. Here is my question: Would the best way to do this be connecting to sql and incrementing a value each time the page loads, then checking if it's divisble by 100 or something? Or is there a better way to do this? I'm also open to other methods to make it random and not bug the hell out of people. Thanks Dan Quote Link to comment https://forums.phpfreaks.com/topic/166672-solved-event-on-certain-number-of-pageviews/ Share on other sites More sharing options...
gijew Posted July 20, 2009 Share Posted July 20, 2009 I would say it depends on how many hits you're getting. If you're getting 100,000 hits a day that's a lot on a database for a popup. I'd say use a cookie. Create / update a cookie for each page load. When the cookie reads (x) you do your magic and you reset the cookie counter, etc. Quote Link to comment https://forums.phpfreaks.com/topic/166672-solved-event-on-certain-number-of-pageviews/#findComment-878862 Share on other sites More sharing options...
rhodesa Posted July 20, 2009 Share Posted July 20, 2009 is the count per user, or across the entire site? Quote Link to comment https://forums.phpfreaks.com/topic/166672-solved-event-on-certain-number-of-pageviews/#findComment-878865 Share on other sites More sharing options...
dhorn Posted July 21, 2009 Author Share Posted July 21, 2009 It's across the entire site. So every certain number of pageviews from different people, the survey will pop-in. If my understanding of cookies is correct, they are stored locally, so that wouldn't work. I need a way to increment something serverside to keep track of how many people have used it. There is no way it's going to get 100,000 hits a day either. More like... a few hundred. Any suggestions on the best method to perform this? Quote Link to comment https://forums.phpfreaks.com/topic/166672-solved-event-on-certain-number-of-pageviews/#findComment-879443 Share on other sites More sharing options...
rhodesa Posted July 21, 2009 Share Posted July 21, 2009 i would use MySQL. but the way i would do the check is not in the script of the page that is loading. since you are already doing a pop-in, which will require javascript, use a script include to a PHP page. have that page add a row to a MySQL table with an auto increment field in it. then, use mysql_insert_id to get that value. finally, run a delete to remove any rows that are less then that id. then, use whatever formula you want to determine if this person should get the pop-in. if so, return the JS code needed to show the pop-in. the key to this is to do all this mysql/php code in a separate file. this way it won't affect the loading time of your page. does that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/166672-solved-event-on-certain-number-of-pageviews/#findComment-879451 Share on other sites More sharing options...
dhorn Posted July 22, 2009 Author Share Posted July 22, 2009 I think I follow what your saying, but I thought of a different method that doesn't involve mysql. I am just going to use the PHP random number generator function to generate a number say 1-5, then only when it equals 5 will the popup display. It may not be as exact as using mysql, but the survey isn't all that important. Thank you for the help though Dan Quote Link to comment https://forums.phpfreaks.com/topic/166672-solved-event-on-certain-number-of-pageviews/#findComment-880548 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.