Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chrisgeary92's avatar

PHP & Servers Hosts File?

I have a personal project that I'd like to start working on, but I'm a little stuck on a potential feature that I'd like to add.

Basically, I want to provide a service online that allows people to add their domain name, and IP address and preview their website before their DNS has updated. Just like what you would do if you updated the hosts file on your own machine.

Does anything know how I could go about doing this? All I can think of is that I have PHP write to /etc/hosts file, but that doesn't seem quite right.

This is the kind of thing I'd like to do: http://hosts.cx/

Thanks in advance :)

0 likes
3 replies
ian_h's avatar

@chrisgeary92 Hmm, you could possibly use Guzzle (or vanilla Curl) if I understand you correctly.

For example, you can hit a server's IP address and specify the hostname as a header manually; eg:

curl ip.address.goes.here -H "www.mydomain.com"

curl ip.address.goes.here -H "a.differentdomain.org"

Both of these would hit the same IP address, but retrieve different sites hosted on them as you're specifying the host (you can run the above on the command line to see what I mean for quick reference).

Maybe this is one method of doing it?

Building an entire application around this concept is a bit too involved for a reply here however.

Food for thought? =)

Cheers..

Ian

chrisgeary92's avatar

Cheers for the info guys. It doesn't have to be PHP, but I'll use PHP for the client facing application so if it's possible with PHP then I'll go with that.. I'll look into it a little more, but I suspect both solutions would work, but would imagine a DNS server would be best.

Please or to participate in this conversation.