HrefCount is a PHP library that register in database how many times a link is clicked by user

dev-master 2018-03-14 23:53 UTC

This package is not auto-updated.

Last update: 2022-08-06 17:48:40 UTC


HrefCount is a PHP library that register and store in database, how many times a link is clicked by user.


Install the latest version with

$ composer require emoretti/href-count ^dev-master


Change the attribute in hrefCountConfig class as you needed.

  1. Change with your site base url

    	private $BASE_URL = "http://<yoursite>/"; 
  2. You can change the key for the query string variable

    	private $QUERY_STRING_VAR_NAME = "qs"; 
  3. 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.

	use emoretti\hrefcount\hrefCount;

	$HC =  new hrefCount(); 


		<title>Click Counter Example</title>


		<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/>


In any linked page you want count the click add

	use emoretti\hrefcount\hrefCountEndpoint;

	$HC_EP =  new hrefCountEndpoint();



Ettore Moretti - info@ettoremoretti.com - https://twitter.com/emoretticom - https://www.facebook.com/emoretticom/


href-count is licensed under the MIT License - see the LICENSE file for details