Ex. I have site with posts. When someone view some post, the post views counts +1.
What i want...
is it possible to count the post views +1 only when the visitros view that post for 10 or more seconds?
if its possible, how can i do that?
Sorry for my bad english.
Is this possible?
Moderator: General Moderators
Re: Is this possible?
Your english is much better than I could write in your language, I am sure. No problem.turulojko wrote:Ex. I have site with posts. When someone view some post, the post views counts +1.
What i want...
is it possible to count the post views +1 only when the visitros view that post for 10 or more seconds?
if its possible, how can i do that?
Sorry for my bad english.
Someone else may have a better answer for you, but my first thought would be to have a Javascript function that starts a timer in the <body onload= event, and after 10 seconds it sends an asynchronous HTTP request, like Ajax, that calls a PHP script that updates the number of views in your database. Maybe there's a simpler way.
- lonelywolf
- Forum Commoner
- Posts: 28
- Joined: Tue Jun 10, 2008 6:15 am
Re: Is this possible?
You can create a session variable to check whether increases post view or not.
Code: Select all
$newsExpire = 10; //unit: second
if(!isset($_SESSION['newsViewSpam'])
|| (time() - $_SESSION['newsViewSpam'] > $newsExpire))
{
//query DB to increase your post view
//...
//assign new timer
$_SESSION['newsViewSpam'] = time();
}-
WebbieDave
- Forum Contributor
- Posts: 213
- Joined: Sun Jul 15, 2007 7:07 am
Re: Is this possible?
Employing a session will not afford him the ability to discern how may seconds a visitor was on particular page. The Ajax suggestion would work, though.lonelywolf wrote:You can create a session variable to check whether increases post view or not.
For non-Ajax platforms, perhaps a hidden iframe that loads the logging page after 10 seconds.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: Is this possible?
My initial suggestion would have been the same as califdon's.
But I think you could also use a session. It would only work when moving to another page within your site but wouldn't require JavaScript. Then you could augment that behaviour for users with JavaScript available to work even when leaving your site by sending an AJAX request on page unload and computing the difference from the last session time. Does that make sense?
But I think you could also use a session. It would only work when moving to another page within your site but wouldn't require JavaScript. Then you could augment that behaviour for users with JavaScript available to work even when leaving your site by sending an AJAX request on page unload and computing the difference from the last session time. Does that make sense?
-
WebbieDave
- Forum Contributor
- Posts: 213
- Joined: Sun Jul 15, 2007 7:07 am
Re: Is this possible?
Right. I guess it comes to down to the accuracy required by the OP.ole wrote:It would only work when moving to another page within your site but wouldn't require JavaScript.