How to go to a website on a shared server by its ip address?

Solution 1:

In your PHP script, when you access it by IP address, you also need to send a Host: header in your request with the correct domain name.

This question on Stack Overflow explains how to do it: https://stackoverflow.com/questions/356705/how-to-send-a-header-using-a-http-request-through-a-curl-call

Solution 2:

As wallyk said, it is virtual servers

Take this example for apache

<VirtualHost *:80>
ServerName example2.com
DocumentRoot C:/www/example2.com
</VirtualHost>

<VirtualHost *:80>
ServerName example.com
DocumentRoot C:/www/example.com
</VirtualHost>

In c:\www\example.com make an index file saying "Hello World! example.com"

in c:\www\example2.com make an index file saying "Hellow World! example2.com"

And change your hosts file to

127.0.0.1 example.com
127.0.0.1 example2.com

Then go to http://example.com then go to http://example2.com

So that is how you can have multiple sites per single ip

So basically the answer is, no you won't be able to get that site from the ip.

Solution 3:

You say you want to manually specify both the the host name and the IP address, instead of relying on a DNS server outside of your control. Looking at the comments at the file_get_contents documentation, I see commenters there have solved similar problems by creating a context that contains the needed Host: header. Something like this:

$context = stream_context_create(array('http' => array('header' => 'Host: www.allaboutcircuits.com')));
$data = file_get_contents('http://68.233.243.63/', 0, $context);

Of course, be aware that the disadvantage to manually specifying both the host name and the IP address is that if the IP address changes in the future (for example, if the site moves to a new hosting provider), your code could stop working until you manually update the IP address.