This application is a simple PHP-based hit counter that tracks and displays the number of hits for specific URLs. It also supports generating charts in multiple formats to visualize the data.
- Tracks hits for specific URLs.
- Generates charts in the following formats:
- Live (SVG) using
ChartJS-PHP - PNG using
jpgraph - SVG using
Maantje Charts
- Live (SVG) using
- Lists all saved directories with their hit counts and links.
- Accessible only with a secret key for secure operations.
-
Clone the repository and navigate to the project directory:
git clone <repository-url> cd hit-counter-php
-
Install dependencies using Composer:
composer install
-
Configure the
.envfile with your database credentials and secret key:DB_HOST=localhost DB_DATABASE=hits DB_USERNAME=your_username DB_PASSWORD=your_password DB_CHARSET=utf8mb4 SECRET_KEY=your_secret_key
-
Set up the database using the
setup-dbtarget in the Makefile:make setup-db
-
Start a local PHP server for testing:
php -S localhost:8000 -t app
To track hits for a specific URL, make a GET request with the url parameter:
curl "http://localhost:8000/index.php?url=example.com"To generate charts, use the chart and chart_type parameters:
-
Live Chart (SVG):
curl "http://localhost:8000/index.php?url=example.com&chart=true&chart_type=live" -
PNG Chart:
curl "http://localhost:8000/index.php?url=example.com&chart=true&chart_type=png" -
SVG Chart (Maantje):
curl "http://localhost:8000/index.php?url=example.com&chart=true&chart_type=svg"
The chart_type parameter is optional. If not provided, the SVG counter will not include a clickable link. When specified, it determines the type of chart to display when the counter is clicked.
Example:
curl "http://localhost:8000/index.php?url=example.com&chart_type=svg"You can customize the title text displayed in the SVG counter by using the title parameter in the URL. If no title is provided, the default is an eye emoji (👀).
Example:
curl "http://localhost:8000/index.php?url=example.com&title=CustomTitle"Large hit counts are automatically formatted for readability. For example:
1500is displayed as1.5 k300000is displayed as300 k1500000is displayed as1.5 M
You can customize the background colors and title text of the SVG counter using the following parameters:
count_bg: Sets the background color of the hit count section (default:#79C83D).title_bg: Sets the background color of the title section (default:#555555).title: Sets the title text (default: 👀).
Example:
curl "http://localhost:8000/index.php?url=example.com&count_bg=%23FF5733&title_bg=%23000000&title=Hits"To list all saved directories with their hit counts and links, use the list parameter with the secret key:
curl "http://localhost:8000/index.php?list=your_secret_key"<html>
<head><title>Saved Directories</title></head>
<body>
<h1>Saved Directories</h1>
<table border="1">
<tr>
<th>URL</th>
<th>Hits</th>
<th>Hit Link</th>
<th>Chart Links</th>
</tr>
<tr>
<td>example.com</td>
<td>42</td>
<td><a href="?url=example.com">Hit Link</a></td>
<td>
<a href="?url=example.com&chart=true&chart_type=live">Live Chart</a> |
<a href="?url=example.com&chart=true&chart_type=png">PNG Chart</a> |
<a href="?url=example.com&chart=true&chart_type=svg">SVG Chart</a>
</td>
</tr>
</table>
</body>
</html>This project is licensed under the MIT License. See the LICENSE file for details.