PHPackages                             jpkleemans/htaccess-firewall - 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. jpkleemans/htaccess-firewall

ActiveLibrary

jpkleemans/htaccess-firewall
============================

Simple access control using Htaccess

3311PHP

Since Mar 22Pushed 9y ago2 watchersCompare

[ Source](https://github.com/jpkleemans/htaccess-firewall)[ Packagist](https://packagist.org/packages/jpkleemans/htaccess-firewall)[ RSS](/packages/jpkleemans-htaccess-firewall/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Htaccess Firewall
=================

[](#htaccess-firewall)

[![Build Status](https://camo.githubusercontent.com/378b7085b0a924a217b5b330c3248feae4ed8a13e5a3b84f3e32123694fad1fd/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a706b6c65656d616e732f68746163636573732d6669726577616c6c2e737667)](https://travis-ci.org/jpkleemans/htaccess-firewall)[![Code Quality](https://camo.githubusercontent.com/b66f77c5a2449cabd642901ebc908e9947e5b96bca55d62fb2e831733b8ddacf/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6a706b6c65656d616e732f68746163636573732d6669726577616c6c2e737667)](https://scrutinizer-ci.com/g/jpkleemans/htaccess-firewall/)[![License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE.md)

[![SensioLabsInsight](https://camo.githubusercontent.com/071464d0b85db227f6765a04402f13ecb6351b5ee245102f365fa478ea35e912/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f30316163313237322d656336392d343361622d623931382d6262656439383938653037332f6269672e706e67)](https://insight.sensiolabs.com/projects/01ac1272-ec69-43ab-b918-bbed9898e073)

Simple access control using Htaccess.

> This library is currently under development. Things will change!

Install
-------

[](#install)

Via Composer

```
$ composer require jpkleemans/htaccess-firewall:dev-master
```

Usage
-----

[](#usage)

First, create an instance of the `HtaccessFirewall\HtaccessFirewall` class:

```
$firewall = new HtaccessFirewall('path/to/.htaccess');
```

### Block IP

[](#block-ip)

```
$host = IP::fromString('123.0.0.1');

$firewall->deny($host);
```

### Unblock IP

[](#unblock-ip)

```
$host = IP::fromString('123.0.0.1');

$firewall->undeny($host);
```

### Get all denied hosts

[](#get-all-denied-hosts)

```
$hosts = $firewall->getDenied();
```

### Deactivate firewall (comment .htaccess lines)

[](#deactivate-firewall-comment-htaccess-lines)

```
$firewall->deactivate();

// And to reactivate:
$firewall->reactivate();
```

### Set 403 message

[](#set-403-message)

```
$hosts = $firewall->set403Message('You are blocked!');

// And to remove:
$hosts = $firewall->remove403Message();
```

Use other filesystem
--------------------

[](#use-other-filesystem)

You can use another filesystem by passing it as the second argument of the `HtaccessFirewall` constructor. The filesystem must implement the `HtaccessFirewall\Filesystem\Filesystem` interface.

```
$filesystem = new YourCustomFilesystem();
$firewall = new HtaccessFirewall('path/to/.htaccess', $filesystem);
```

Testing
-------

[](#testing)

```
$ phpspec run
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b4ef8e7738c77130e1cc63ff7f0503e25c5757145c9ac17cfabc380cba37143?d=identicon)[jpkleemans](/maintainers/jpkleemans)

---

Top Contributors

[![jpkleemans](https://avatars.githubusercontent.com/u/5700014?v=4)](https://github.com/jpkleemans "jpkleemans (67 commits)")

---

Tags

allowdenyfirewallhtaccess

### Embed Badge

![Health badge](/badges/jpkleemans-htaccess-firewall/health.svg)

```
[![Health](https://phpackages.com/badges/jpkleemans-htaccess-firewall/health.svg)](https://phpackages.com/packages/jpkleemans-htaccess-firewall)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
