Search code examples
phphtmlhttp-host

What am I doing wrong while getting URL


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.