emoretti / href-count
HrefCount is a PHP library that register in database how many times a link is clicked by user
Requires
This package is not auto-updated.
Last update: 2025-03-02 07:32:36 UTC
README
HrefCount is a PHP library that register and store in database, how many times a link is clicked by user.
Installation
Install the latest version with
$ composer require emoretti/href-count ^dev-master
Configuration
Change the attribute in hrefCountConfig
class as you needed.
-
Change with your site base url
private $BASE_URL = "http://<yoursite>/";
-
You can change the key for the query string variable
private $QUERY_STRING_VAR_NAME = "qs";
-
Set your database connection data
private $DATABASE_NAME = "test"; private $DATABASE_USR = "root"; private $DATABASE_PWD = ""; private $TABLE_NAME = "href_count"; ```
Basic Usage
Create an instance of hrefCount()
class in the page you will use the HTML a tag.
In the href attribute, insert the call to the href() method, passing the "link" and "alias" values.
<?php use emoretti\hrefcount\hrefCount; $HC = new hrefCount(); ?> <html> <head> <title>Click Counter Example</title> </head> <body> <h1>Click Counter PHP - Example use</h1> <h2>Click a link to increase the relative counter.</h2> <h3>Same Page link</h3> <a href="<?php $HC->href('index.php','Homepage') ?>">Homepage</a><br/> <h3>Same Page link with get parameter</h3> <a href="<?php $HC->href('index.php?test=hello','Homepage_Hello') ?>">Homepage with query string</a> <h3>Same page with #anchor link</h3> <a href="<?php $HC->href('#ancorar','Homepage_anchor') ?>">Homepage with Anchor</a><br/> <h3>Another page link</h3> <a href="<?php $HC->href('link1.php','Another page') ?>">Link1</a><br/> </body> </html>
In any linked page you want count the click add
<?php use emoretti\hrefcount\hrefCountEndpoint; $HC_EP = new hrefCountEndpoint(); ?>
Author
Ettore Moretti - info@ettoremoretti.com - https://twitter.com/emoretticom - https://www.facebook.com/emoretticom/
License
href-count is licensed under the MIT License - see the LICENSE
file for details