Making usage statistics on a web site is one of the most enjoyable things for me on the Internet. Thanks to the technology, you can see each click of each visitor, the date of the visiting, and how many seconds the user was reading your site. I use this feature to track which of my articles was read for the longest time. In this article I will show you how to store the statistics in a MySQL database, show the web stats in an HTML table and make figures based on the stats using the GD library.
Making Usage Statistics in PHP - Save the HTML Title (Page 2 of 7 )
As I've already mentioned above, it can be useful to save the HTML title of the page. We'll use header.php to show the <title></title> HTML tag. My solution to know the HTML title is to define this PHP constant 'TITLE'. I define it in the index.php, before it includes header.php.
// showing a topic using given data define('TITLE', "Adam's forum > Topic: $topicname"); include('header.php') // here comes the main part
Now the included header.php can save the TITLE constant. Here's the query to save the data. Put this piece to the beginning of the header.php.
$q
='insert into hits (Host, Site, Title, Date) values ("'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'", "'.addslashes($_SERVER['QUERY_STRING']).'", "'.addslashes(TITLE).'", now())'; mysql_query($q) or print(mysql_error());
Details explained above. Note addslashes() that's necessary when writing strings in a database because of the hacking attempts. This is some kind of encoding method, so you'll need to decode it when you write the string out by the stripslashes() function.