https://github.com/droath/hostsfile-manager
Manage the system hosts file using PHP.
https://github.com/droath/hostsfile-manager
hosts hostsfile php
Last synced: 12 months ago
JSON representation
Manage the system hosts file using PHP.
- Host: GitHub
- URL: https://github.com/droath/hostsfile-manager
- Owner: droath
- Created: 2017-03-22T01:54:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-22T15:06:51.000Z (over 9 years ago)
- Last Synced: 2025-02-26T17:48:39.767Z (over 1 year ago)
- Topics: hosts, hostsfile, php
- Language: PHP
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hosts File Manager
[](https://travis-ci.org/droath/hostsfile-manager)
Provides a class to add/remove lines from the hosts file. It has been tested to work on *nix based systems, otherwise you'll need to supply the path to the hosts file.
## Getting Started
First, you'll need to download the hostsfile manager library using composer:
```bash
composer require droath/hostsfile-manager:^0.0.1
```
## Examples
**Add lines to the hosts file contents:**
The below code appends two entries to the hosts file contents. If any of those lines already exists then nothing is appended.
```php
setLine('127.0.0.1', 'local.sickslap.com')
->setLine('127.0.0.2', 'local.hiphopsmack.com');
(new \Droath\HostsFileManager\HostsFileWriter($hosts_file))
->add();
```
**Remove a single line from hosts file:**
The below code removes the one entry from the hosts file. All other lines within the hosts file remain untouched.
```php
setLine('127.0.0.2', 'local.hiphopsmack.com');
(new \Droath\HostsFileManager\HostsFileWriter($hosts_file))
->remove();
```