Is it possible to print the name of the domain where a file exists with PHP? I want to upload the file to a website, say websites.com, and when i view the file i want it to just say "websites.com", without writing echo "websites.com";. Any suggestions on how i should write this?
The superglobal $_SERVER['HTTP_HOST'] should contain the domain url. NON WWW $domain = parse_url($_SERVER['HTTP_HOST']); echo $domain['host']; PHP: OR WWW $domain = parse_url($_SERVER['HTTP_HOST']); echo 'www.' .'$domain['host']'; PHP: OR http://www. $domain = parse_url($_SERVER['HTTP_HOST']); echo 'http://www.' .'$domain['host']'; PHP: I parsed the URL for all three of them because if a visitor is visiting either the www or non www version of the website you can still get the same result.
Following link would be very helpful if you wish to know complete path of the link including HTTPS status as well as PORT. http://www.webcheatsheet.com/PHP/get_current_page_url.php