Forum Moderators: coopster
It should get the following information about the user and store them in the mysql database
User IP
Referrer
Landing Page
Pages visited during visit
Number of visits during the day
Time spent on visit
How this can be done,any hint in this regard will be highly appreciated
Please also let me know if there are some already made scripts for doing the same
Save the session_id() into the database and each time someone visits the page you have to check their session_id() and see if it matches an ID in the database. If it does then update their info (number of pages viewed this visit, total daily page views, etc.) otherwise put in a new entry. There is a good amount of coding to accomplish this but you can find all the information you need to do it out on the web.
Hope this helps!
$ip = $REMOTE_ADDR;
if ($var_ip!="your_own_ip_here_if_you don't_want_tol_log_your_own_pageviews")
{
$date = date("Y/m/d");
$time = date ("h:i:s A");
$agent= $HTTP_USER_AGENT;
$referrer = $HTTP_REFERER;$host="db_host_probably_localhost";
$user="db_username";
$password="db_password";
$dbname="db_name";$connect=mysql_connect($host,$user,$password);
mysql_select_db($dbname, $connect);$sql="INSERT INTO pageviews (date, time, agent, ip, referrer) VALUES ('".$date."', '".$time."','".$agent."','".$ip."','".$referrer."')";
mysql_query($sql);
echo mysql_errno() . "error: " . mysql_error();
mysql_close();
}
This simply writes the info to the database every time the page is requested. To find out advanced stuff like 'time spent', 'landing page', etc, you can't do without sessions.