The King is The King is - 3 months ago 15
PHP Question

Subdomain URL throws back PHP error

When I run this code I have no problem

$base = 'http://localhost';
include $base.'/header.php';


But I added a sub-domain to my WAMP server for mobile and if I try to run a similar code

$base = 'http://m.localhost';
include $base.'/header.php';


I get this error


Warning: include() [function_include]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\wamp\www\mobile\index.php on line 20

Warning: include(http://m.localhost/header.php) [function_include]: failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\wamp\www\mobile\index.php on line 20


What I can see is that 'localhost' is recognized by the script but 'm.localhost' isn't. Please anyone with an idea on how to solve this issue

Answer

I did ran into a similar situation and this helped me.

Go to the host file located at C:\Windows\system32\drivers\etc\host and add this to the file

127.0.0.1      m.localhost

Note: if m.localhost is your sub-domain name then add the above code else you replace m.localhost with your desired sub-domain name. And also restart your WAMP server