|
I've got a small web server set up that I use for random things. But the thing is, my IP changes randomly because the server is run from my home and the cable company changes customers' IP every so often. So every link I made is now broken as it's trying to find my old IP.
I found a small solution by using:
$_SERVER['HTTP_HOST'];
which gives me my ip address (ie: 127.0.0.1) and i simply put it into a link tag. But it's not working for my main folder, only sub folders.
ie: works for http://127.0.0.1/blog.index.php
but not for http://127.0.0.1/index.php
Is there any code that I can use that will display the domain name or ip address no matter what sub folder im in?
PHP: code to display domain name/ip address?
The full path name is returned with
$_SERVER['DOCUMENT_ROOT'];
Your current server IP is returned with
$_SERVER['SERVER_ADDR'];
PHP: code to display domain name/ip address?
If you design using relative links you wouldn't have this problem.
Anyway, try $_SERVER['SERVER_ADDR'] instead of HTTP_HOST.
PHP: code to display domain name/ip address?
http://127.0.0.1/index.php
This should work, may be some other reason. You your web server access log to see what it says when you access this main page.
PHP: code to display domain name/ip address?
$_SERVER['SERVER_ADDR'] would work for you.
It would be better to keep all links relative and include a file with the ip or dns variable in.
Have you tried dyndns? It might suit you.
https://www.dyndns.com/
|