PHP Hit Counter
Store count in MySQL database. The count is increased everytime the page is refresh. The counter can be reset by running a PHP script.
For demonstration, look at the hit counter on my homepage.
PHP files needed:
| connect.php | Databse configuration, you need to enter your database username, password, and host. |
| create_database.php | Create a database name 'counter' to store the count value. |
| create_table.php | Create table for database count, the table contains one field: count, which should allow up to 99,999,999 hits. |
| counter.php | Count up the value and display count every time executed. |
| reset_counter.php | This file will reset the count to 0 every time executed. |
Installation
- Fill up the necessary information in connect.php.
- Execute the create_database.php, the database 'counter' will be created. If problems occur, you can manually create a counter database using phpMyAdmin.
- Execute create_tabel.php.
- Include the line "include("dir/counter.php");"in the place where you want the hit counter to appear, where 'dir is the directory your 'counter.php' is stored.
- Just execute reset_counter.php if you want to reset the counter.
- A sample page 'index.php' is included in the download package for better understanding.
Download
PHP Hitcounter

