Page 1 of 1
Is this possible?
Posted: Sat Jun 14, 2008 9:16 pm
by turulojko
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.
Re: Is this possible?
Posted: Sat Jun 14, 2008 10:49 pm
by califdon
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.
Your english is much better than I could write in your language, I am sure. No problem.
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.
Re: Is this possible?
Posted: Sat Jun 14, 2008 11:11 pm
by lonelywolf
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();
}
Re: Is this possible?
Posted: Sun Jun 15, 2008 12:40 pm
by WebbieDave
lonelywolf wrote:You can create a session variable to check whether increases post view or not.
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.
For non-Ajax platforms, perhaps a hidden iframe that loads the logging page after 10 seconds.
Re: Is this possible?
Posted: Mon Jun 16, 2008 3:31 am
by Ollie Saunders
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?
Re: Is this possible?
Posted: Mon Jun 16, 2008 7:03 pm
by WebbieDave
ole wrote:It would only work when moving to another page within your site but wouldn't require JavaScript.
Right. I guess it comes to down to the accuracy required by the OP.