emoretti/href-count

HrefCount 是一个 PHP 库,用于记录用户点击链接的次数并注册到数据库中

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

This package is not auto-updated.

Last update: 2024-09-29 04:48:57 UTC


README

HrefCount 是一个 PHP 库,用于记录并存储用户点击链接的次数到数据库中。

安装

使用以下命令安装最新版本

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

配置

根据需要更改 hrefCountConfig 类中的属性。

  1. 更改您的网站基本 URL

    	private $BASE_URL = "http://<yoursite>/"; 
  2. 您可以根据需要更改查询字符串变量的密钥

    	private $QUERY_STRING_VAR_NAME = "qs"; 
  3. 设置您的数据库连接数据

    	private $DATABASE_NAME = "test";
    	private $DATABASE_USR = "root";
    	private $DATABASE_PWD = "";
    	private $TABLE_NAME = "href_count"; ```
    

基本用法

在您将要使用 HTML a 标签的页面中创建 hrefCount() 类的一个实例。在 href 属性中,插入对 href() 方法的调用,传递 "link" 和 "alias" 值。

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

在您想要计数的任何链接页面中添加

<?php
	
	use emoretti\hrefcount\hrefCountEndpoint;

	$HC_EP =  new hrefCountEndpoint();

?>

作者

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

许可证

href-count 使用 MIT 许可证授权 - 详细信息请参阅 LICENSE 文件