Link to home
Start Free TrialLog in
Avatar of CodilX
CodilX

asked on

PHP visitor duration

I'm trying to make a php script that indexes durations of page views on my site.

I've been doing some fiddling but I've hit a dead end, here's what I've come up so far:

1. every time the page is loaded, a random token is created and save as $_SESSION["token"] == $random;
2. a php file checks if the token is in the mysql database, if found, it updates the duration by 1. if not found, it creates a new entry and the cycle begins all over again

now, the only problem is that I need to refresh the site every second to be able to add +1 value to the duration, so I tried making an invisible iframe to do that and added a javascript reload timer, but even though the website doesn't fully refresh, you can still signs of something refreshing. then I tried making a while(0==0) { ... sleep(1); } loop inside the php script, but it somehow overflows the server and the page fails to load.

does anyone have an idea how to refresh the .php file embedded some way in the site without any visible activity?

maybe this could be done with ajax? the problem is that I don't know anything about it :/
ASKER CERTIFIED SOLUTION
Avatar of AlexanderR
AlexanderR
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CodilX
CodilX

ASKER

thank you so much :) works like a dream