Jump to content

Recommended Posts

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

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.

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?

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?

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.