Vermillion Posted May 1, 2009 Share Posted May 1, 2009 Hi guys. I am having a weird problem here: Can someone tell me why when I do this: '<a href="'.$_SERVER['HTTP_HOST'].'/login/">Login</a>' The link becomes this?: http://www.projectawings.com/www.projectawings.com/login/ That really shouldn't be happening, I should only see: www.projectawings.com/login/ or http://www.projectawings.com/login/ It happens on my localhost as well. it does: http://localhost/localhost/login/ I really want to find a solution to this one . Any help will be appreciated! Link to comment https://forums.phpfreaks.com/topic/156376-solved-_serverhttp_host-problem/ Share on other sites More sharing options...
WolfRage Posted May 1, 2009 Share Posted May 1, 2009 Try $_SERVER['SERVER_NAME'] . Link to comment https://forums.phpfreaks.com/topic/156376-solved-_serverhttp_host-problem/#findComment-823300 Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted May 1, 2009 Share Posted May 1, 2009 <?php echo '<a href="http://'.$_SERVER['HTTP_HOST'].'/login/">Login</a>'; ?> Since you don't have the http:// the browser assuming www.projectawings.com is a directory and add the domain name before. Link to comment https://forums.phpfreaks.com/topic/156376-solved-_serverhttp_host-problem/#findComment-823383 Share on other sites More sharing options...
Vermillion Posted May 1, 2009 Author Share Posted May 1, 2009 Thanks both. I tried theonlydrayk's solution and that one worked wonderfully . Link to comment https://forums.phpfreaks.com/topic/156376-solved-_serverhttp_host-problem/#findComment-823631 Share on other sites More sharing options...
the182guy Posted May 1, 2009 Share Posted May 1, 2009 Don't rely on the HTTP_HOST variable for your links. This variable is provided by the web browser when it transmits a request for a webpage. Which means someone could change the value of it. You'd be better off setting a variable with the site URL and just use that. Link to comment https://forums.phpfreaks.com/topic/156376-solved-_serverhttp_host-problem/#findComment-823679 Share on other sites More sharing options...
Vermillion Posted May 1, 2009 Author Share Posted May 1, 2009 I was told it wasn't recommended as well... But I don't want to use a variable for that. I think I will see about using relative paths and that stuff. Link to comment https://forums.phpfreaks.com/topic/156376-solved-_serverhttp_host-problem/#findComment-823723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.