General Statistics
390 Tutorials
202 Total Votes
13 User(s) Online
747239 Views Total
3000 Registered Members
24435 Posts Total
Rooneyfeld is our newest member
About this Tutorial: Display Total and Unique Hits on Your Site
Display Total and Unique Hits on Your Site
Rated 5 / 4 Votes

Display Total and Unique Hits on Your Site

Learn how to display the total number of visits and total number of unique visits to your site using PHP and MySQL.


Date Added: December 24, 2005 [ 11674 Views - 4 Votes ] [ Rate ]

Author: Boost [ PHP Coding ] [ 10 Comment(s) ]

Display Total and Unique Hits on Your Site
Now that we have our MySQL table set up, we need to create a file called stats.php. In this file we will have all of our code.

The first segment in ths code will be to connect to the MySQL table.
CODE
<php

//---------------------
// Define Some Connection Info
//---------------------

$host = 'hostname';
$username = 'username';
$password = 'password';
$db_name = 'database_name';
$tbl_name = 'stats'; // table name (should be correct unless changed in the mysql query)


This code defines some variables for us, so conecting to the database is easier, instead of typing all of this information in. It is pretty self explanatory.

This next chunk of code actually connects to the Database (It will be explained below)

CODE
//---------------------
// Connect To the Database
//---------------------

$sql_connect = mysql_connect("$host", "$username", "$password") or die("MySQL Connection Failed: " . mysql_error());;
$db_connect = mysql_select_db("$db_name")or die("Could not select DB: " . mysql_error());;

mysql_connect connects to our MySQL database using the variables we defined above. If it fails in connecting it will print the mysql error.
mysql_select_db selects the db which we will be storing our information in. Once again, if it fails, it will print the mysql error.

Now we can go on to the actual code of our script.

Total Pages (4)
<<Prev 1 [2] 3 4 Next>>

Welcome User
Welcome Guest
( Login | Register )

Latest Tutorial Index - RSS Feed
Latest Resources - RSS Feed
Latest Tutorials - RSS Feed
Vote for Us
  • VixxIMG.com - Free Image Hosting, Free Myspace Image Hosting, Free Image Uploads
  • PageRank Plus - Google PageRank checking, with a twist.
Random Affilaites