Sunday, September 21, 2008

Hits count of a site using PHP

Suggestion for Hit count:

1. Create table to store the
hit counts into Database.

2. That table having the fields like
(a.) auto_increment_id (Primary Key)
(b.) file_name
(c.) user_ip_address
(d.) date_time_visit

3. Write an INSERT query to insert a record into the Database
Query: INSERT INTO table_name
SET file_name = 'VALUE1',
user_ip_address = 'VALUE2',
date_time_visit = 'VALUE3'


VALUE1 -- basename($_SERVER['PHP_SELF'])

VALUE2 -- $_SERVER['REMOTE_ADDR']

VALUE3 -- date('Y-m-d H:i:s')

4. VALUE1 is used to store for which filename visited by the user

5. VALUE2 is used to store the IP address of the visited user

6. VALUE3 is used to store the visited time of the user

7. Write the INSERT in (STEP 3) on your common areas
i.e. Header or Footer or leftpanel, or other regions loaded every time on every files in our site

8. If you want Total number of hits of all the files i.e. our entire site ?

Query : SELECT count(auto_increment_id) FROM tablename

this query answers for this question

9. Total number of hits for a particular file i.e. login.php

$current_filename = basename($_SERVER['PHP_SELF']);

Query: SELECT count(auto_increment_id) FROM tablename WHERE filename = '$current_filename';

this query answer for this question

Conclusion:
I hope you got some idea about getting the hit count using PHP..

1 comment:

navya said...

I have read your blog its very attractive and impressive. I like it your blog.

PHP Training in chennai | PHP Training Course

PHP Training in chennai | Online PHP Course

Popular Posts