August 25, 201016 yr Hey, just a question on whether or not this possible. What I'm after is when a user clicks a link 5 times in a row, on the 5th click it opens a popup in the another window. But then after that it counts another 5 clicks, etc... e.g 1 click 2 click 3 click 4 click 5 POPUP 1 click 2 click 3 click 4 click 5 POPUP etc... [i'm sure you get the picture] Now I know you can count clicks quite well in php, so I was thinking, maybe this would work best with an if php if statement? Just wondering how you guys would go about doing this? I know javascripts always an option. But could anyone enlighten me to a good way of doing this? One of the draw backs of the PHP method would be wouldn't it mark the link count at 10 for ALL the users unless is was specified to count the links using the users IP? But like I said, just wondering how you'd do this. All suggestions welcome Thankya!
August 25, 201016 yr Not sure why you think PHP will do this but it definitely won't. You also can't count clicks with php either, so not sure where you've heard that They way to go about this is through JavaScript. There really is no other way
August 25, 201016 yr Author Not sure why you think PHP will do this but it definitely won't. You also can't count clicks with php either, so not sure where you've heard that They way to go about this is through JavaScript. There really is no other way I actualy found quite a few php scripts that claimed to count clicks, just what I managed to find when I was searching. But thanks for the reply. I'll take a look at some javascript scripts. Thanks.
August 25, 201016 yr Ah wait, do you mean how do you track a script being executed by php? you can do that with php, is that what you meant?
August 25, 201016 yr I think the confusion is you read it as when the user clicks 5 times on a link a window needs to open, and obviously a server side language cant do that - it's a browser based event. I read it like that too though! I think he just means when a user clicks on a link, the application stores that and on every fifth click provides a popup. Pippin, is that what you meant? We'd need some more information about this, but it's definitely possible. For example, does your application have a user system, and do they have to be logged in to access these links? If not then yes, you'd be forced to use some other method to keep track - IP tracking is one as you mentioned. The other would be to use cookies (this will allow for the count to be retained between visits). Be aware that a determined user can get around either of these with ease though (proxies and rejecting cookies respectively). As far as how PHP counts the click there are a few approaches you could take just off the top of my head - could you confirm exactly what you need first?
August 25, 201016 yr You can count clicks with php, but not in a way that would be practical for what you're doing (it's not really counting the clicks, but the http requests following a link click). You could use php/ajax if you needed to keep a log of the activities, otherwise pure JS would be sufficient (this can be disabled).
August 25, 201016 yr This is a basic idea of how you would count clicks in jQuery, it probably won't work out the box i've just written it as a crude example, and it obviously breaks the link function. var count = 0; $(".count a").click( function() { count++; if (count == 5) { alert('Basic Alert'); count = 0; } return false; } You would probably be far better using ajax to pass the information to a php script for processing, and logging.
August 25, 201016 yr That's how I imagined it to start with bocaj, but I think crisp is right and it's just a script tracker showing an ad after so many page views to something
August 25, 201016 yr That's how I imagined it to start with bocaj, but I think crisp is right and it's just a script tracker showing an ad after so many page views to something Yeah but i already wrote my post when i read his reply, and i didn't wanna delete it
August 25, 201016 yr Author Sorry about the late reply been quite busy today. @crisp Thanks, yeah yeah sorry I didn't explain myself well, yes, this is exactly what I need. [although it would need to open a separate window] But the users don't have a login system, which Is why I thought there maybe an issue with the Ip's and such. So maybe the IP tracking or cookies would be better? I understand about people being able to get around these fairly easily, i'd rather have it more secure, quite obviously, but if it's unavoidable it's not that much of a problem Thanks alot also for the other options. I think the code bocaj suggested would be the kind of thing I wanted. So thanks for that bocaj But on a side note, this has to be different for different users. Will this code suffice for something like that? Or will it apply the count number to all the users? But exactly what I want is: When a user clicks on a link, the application stores that and on every fifth click provides a new window. But it has to treat each user individually. So each user gets 5 clicks before the popup Hope this helps clarify Thanks for all the input so far.
August 27, 201016 yr I think the easiest way is to store a session cookie. Update a value each time the link is clicked. Also check if the limit is reached. If it is then display the popup.
Create an account or sign in to comment