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! Quote Link to comment Share on other sites More sharing options...
WolfRage Posted May 1, 2009 Share Posted May 1, 2009 Try $_SERVER['SERVER_NAME'] . Quote Link to comment 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. Quote Link to comment 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 . Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.