Skip to content

droath/hostsfile-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hosts File Manager

Build Status

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:

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

    $hosts_file = (new \Droath\HostsFileManager\HostsFile())
        ->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

    $hosts_file = (new \Droath\HostsFileManager\HostsFile())
        ->setLine('127.0.0.2', 'local.hiphopsmack.com');

    (new \Droath\HostsFileManager\HostsFileWriter($hosts_file))
        ->remove();

About

Manage the system hosts file using PHP.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages