PHPackages                             esi/simple\_counter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. esi/simple\_counter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

esi/simple\_counter
===================

A simple web hit counter.

v6.0.1(3mo ago)26366[2 PRs](https://github.com/ericsizemore/simple_counter/pulls)MITPHPPHP ^8.2CI passing

Since Jan 11Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/ericsizemore/simple_counter)[ Packagist](https://packagist.org/packages/esi/simple_counter)[ GitHub Sponsors](https://github.com/ericsizemore)[ Fund](https://ko-fi.com/ericsizemore)[ RSS](/packages/esi-simple-counter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (12)Versions (9)Used By (0)

Simple Counter - A simple web hit counter.
==========================================

[](#simple-counter---a-simple-web-hit-counter)

[![Build Status](https://camo.githubusercontent.com/883811c0175f315fc91830630837cd6f11bf6c1f8cfae8e8538cc80bf9c6d738/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6572696373697a656d6f72652f73696d706c655f636f756e7465722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ericsizemore/simple_counter/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/e060f588ef1dae9a2a7f648302c8738e7cbba8e7ee7ad2d375d4924ea6808872/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6572696373697a656d6f72652f73696d706c655f636f756e7465722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ericsizemore/simple_counter/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/dc52bdc8a05fe20ed5a9572f03cd999b7ee2e12a8d4a96a362c8df15ca8f7670/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6572696373697a656d6f72652f73696d706c655f636f756e7465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ericsizemore/simple_counter/?branch=master)[![Tests](https://github.com/ericsizemore/simple_counter/actions/workflows/tests.yml/badge.svg)](https://github.com/ericsizemore/simple_counter/actions/workflows/tests.yml)[![PHPStan](https://github.com/ericsizemore/simple_counter/actions/workflows/main.yml/badge.svg)](https://github.com/ericsizemore/simple_counter/actions/workflows/main.yml)[![Psalm Static analysis](https://github.com/ericsizemore/simple_counter/actions/workflows/psalm.yml/badge.svg?branch=master)](https://github.com/ericsizemore/simple_counter/actions/workflows/psalm.yml)[![Type Coverage](https://camo.githubusercontent.com/a8faa119e2f386656998144ec2c42bd74d1f876a97cd10d59c6538ca85b2c64b/68747470733a2f2f73686570686572642e6465762f6769746875622f6572696373697a656d6f72652f73696d706c655f636f756e7465722f636f7665726167652e737667)](https://shepherd.dev/github/ericsizemore/simple_counter)[![Psalm Level](https://camo.githubusercontent.com/8c4607b6887ad0cd8671a044c72a337f391837de2169801927d98a6def70e9c7/68747470733a2f2f73686570686572642e6465762f6769746875622f6572696373697a656d6f72652f73696d706c655f636f756e7465722f6c6576656c2e737667)](https://shepherd.dev/github/ericsizemore/simple_counter)[![Quality Gate Status](https://camo.githubusercontent.com/8ce80e08b2fa176a702f5a3d4897fe7dd2f731b4d80137cf1dbb0aa191e5da9b/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6572696373697a656d6f72655f73696d706c655f636f756e746572266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/summary/new_code?id=ericsizemore_simple_counter)[![Latest Stable Version](https://camo.githubusercontent.com/3dba5ea3ed2ceae27f06b757f9958a771d654d090b6e7ea2c9bfff238a83c90e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6573692f73696d706c655f636f756e7465722e737667)](https://packagist.org/packages/esi/simple_counter)[![Downloads per Month](https://camo.githubusercontent.com/2af29869246d8a9beea1a183a5a1602b3f6a2a8c3b70a3442cb9772070f49751/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6573692f73696d706c655f636f756e7465722e737667)](https://packagist.org/packages/esi/simple_counter)[![License](https://camo.githubusercontent.com/da940c52c251e112d18da5cc50aa9ac9c7ab7fc66f80c88d39af550097ec1de1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6573692f73696d706c655f636f756e7465722e737667)](https://packagist.org/packages/esi/simple_counter)

[Simple Counter](https://github.com/ericsizemore/simple_counter/) is a simple PHP counter that counts your website visitors. It has the ability to either show the count as plain text or images; and whether to count only unique hits, or all hits. (IP Based)

Important Note
--------------

[](#important-note)

- As of v6.0.0, Simple Counter is no longer licensed under the GNU LGPLv3 license.
- v6.0.0 is a complete rewrite of the library, and no GNU LGPLv3 licensed code remains.
- v5.0.1 and previous are still licensed under the GNU LGPLv3 license.

With that being said, it is important to read the `Upgrading` section below if you are coming from an older version.

Acknowledgements
----------------

[](#acknowledgements)

The icons used for the default image set (0-9 'png' images found in `counter/images/`) are licensed under the [CC BY 4.0 DEED license](https://creativecommons.org/licenses/by/4.0/), and were designed by [StreamlineHQ](https://www.streamlinehq.com/freebies/typeface).

Upgrading
---------

[](#upgrading)

Pre-v6 -&gt; v6 is not a simple upgrade. Several things have changed in this rewrite, and there are breaking changes.

Please read [UPGRADING.md](UPGRADING.md) first before attempting an upgrade.

Installation
------------

[](#installation)

To install Simple Counter, first install via composer:

```
composer require esi/simple_counter:^6.0
```

There are several options defined by default, however you will likely run into issues if you do not change some of them. More information can be found in [Usage](#usage) below.

- Copy the `counter` directory from `vendor/esi/simple_counter` to your webroot
    - The `counter` directory contains the `logs` and `images` directory.
    - You can change the name of either directory if you wish, or skip using the `counter` directory all together and just move `logs` and `images` to your webroot.
        - However:
            - The ip file and counter file must remain `ips.json` and `counter.json`
            - The images must be named 0-9.
- Make sure the `ips.json` and `counter.json` files within your logs directory are writable.

Usage
-----

[](#usage)

**More detailed documentation is a work in progress.**

Usage is fairly simple once installed. There is currently one option for the type of counter you wish to use, and that is the `FlatfileStorage`. A `DatabaseStorage` is slated for an upcoming release.

Simply add the following code to the page where you want the counter to be shown:

```

```

Handling Errors
---------------

[](#handling-errors)

Simple Counter uses Exceptions for various issues that may arise throughout its process.

Currently, most exceptions fall under `\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException`.

These exceptions can be thrown if:

- You pass an option that is not defined.
- A given option's value type does not match the allowed types.
- When reading/writing to a file encounters an error, since it is likely due to a file name/location issue.
- For invalid directories or files, in terms of `logDir`, `imageDir`, `countFile`, `ipFile`

About
-----

[](#about)

### Requirements

[](#requirements)

- PHP &gt;= 8.2

### Credits

[](#credits)

- [Eric Sizemore](https://github.com/ericsizemore)
- [All Contributors](https://github.com/ericsizemore/simple_counter/contributors)

### Contributing

[](#contributing)

See [CONTRIBUTING](./CONTRIBUTING.md).

Bugs and feature requests are tracked on [GitHub](https://github.com/ericsizemore/simple_counter/issues).

### Contributor Covenant Code of Conduct

[](#contributor-covenant-code-of-conduct)

See [CODE\_OF\_CONDUCT.md](./CODE_OF_CONDUCT.md)

### Backward Compatibility Promise

[](#backward-compatibility-promise)

See [backward-compatibility.md](./backward-compatibility.md) for more information on Backwards Compatibility.

### Changelog

[](#changelog)

See the [CHANGELOG](./CHANGELOG.md) for more information on what has changed recently.

### License

[](#license)

See the [LICENSE](./LICENSE.md) for more information on the license that applies to this project.

#### Important Note

[](#important-note-1)

Simple Counter switched to the `MIT` license as of v6.0.

Version 5.0.1 and older is licensed under the `GNU LGPL v3 License`. See the [`
