简体   繁体   中英

Generating Statistics (Page Views, Unique Visitors) using PHP?

I'm using the following code in the header of every page to try and gather records that I can use to produce website statistics, page views, unique users etc. The code runs without any errors but isn't inserting anything in to the database:

<?php 
include 'connect.php';

$browserType  =  $_SERVER['HTTP_USER_AGENT'];
$ipAddress  =  $_SERVER['REMOTE_ADDR'];
$month = "date('F')";
$year = "date('Y')";

$sqlPageViews  =  "INSERT INTO JB_Statistics ( browser, ip, month, year, recDate) VALUES ( '$browserType' , '$ipAddress' , '$month', '$year', CURDATE() );";
mysql_query($sqlPageViews);
mysql_close();

?>

Is there something missing here or is there a better way of acheiving this?

Well you do not need the

`month` and `year`

in you table because the date stores all of that.

PS try putting this at the end of your page so it stores it last, better for the visitor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM