https://github.com/jpkleemans/htaccess-firewall
Simple access control using Htaccess
https://github.com/jpkleemans/htaccess-firewall
allow deny firewall htaccess
Last synced: 3 months ago
JSON representation
Simple access control using Htaccess
- Host: GitHub
- URL: https://github.com/jpkleemans/htaccess-firewall
- Owner: jpkleemans
- License: mit
- Created: 2015-09-26T13:37:31.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-22T17:22:10.000Z (about 8 years ago)
- Last Synced: 2025-01-29T20:35:35.194Z (5 months ago)
- Topics: allow, deny, firewall, htaccess
- Language: PHP
- Size: 45.9 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Htaccess Firewall
[](https://travis-ci.org/jpkleemans/htaccess-firewall)
[](https://scrutinizer-ci.com/g/jpkleemans/htaccess-firewall/)
[](LICENSE.md)[](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
Via Composer
``` bash
$ composer require jpkleemans/htaccess-firewall:dev-master
```## Usage
First, create an instance of the `HtaccessFirewall\HtaccessFirewall` class:
``` php
$firewall = new HtaccessFirewall('path/to/.htaccess');
```### Block IP
``` php
$host = IP::fromString('123.0.0.1');$firewall->deny($host);
```### Unblock IP
``` php
$host = IP::fromString('123.0.0.1');$firewall->undeny($host);
```### Get all denied hosts
``` php
$hosts = $firewall->getDenied();
```### Deactivate firewall (comment .htaccess lines)
``` php
$firewall->deactivate();// And to reactivate:
$firewall->reactivate();
```### Set 403 message
``` php
$hosts = $firewall->set403Message('You are blocked!');// And to remove:
$hosts = $firewall->remove403Message();
```## 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.``` php
$filesystem = new YourCustomFilesystem();
$firewall = new HtaccessFirewall('path/to/.htaccess', $filesystem);
```## Testing
``` bash
$ phpspec run
```