What am I doing wrong while getting URL [closed]
Question
I want to place links on my page.
I use
echo "<a href=\"".$_SERVER['HTTP_HOST']."/projecten/project.php?project=1";
I want to go to mydomain.nl/project/project.ph?project=1
but instead of that link I get http://mydomain.nl/projecten/mydomain/projecten/project.php?project=1
I thought that
$_SERVER['HTTP_HOST']
would give me http://mydomain.nl
, why isn't it doing this?
Solution
Start your link with http://
, https://
or //
. $_SERVER['HTTP_HOST']
only contains the host, not the protocol.
OTHER TIPS
You need to specify protocol that is http://
echo '<a href="http://'.$_SERVER['HTTP_HOST'].'"/projecten/project.php?project=1';
or for secure link use
echo '<a href="https://'.$_SERVER['HTTPS_HOST'].'"/projecten/project.php?project=1';
you can easy see what configuration is used by this scriplet
<?php
phpinfo();
?>
i thougt what you want is to use $_SERVER["SERVER_NAME"]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow