$_SERVER['HTTP_HOST'] in href?

How to put $_SERVER[‘HTTP_HOST’] in href tag?

You mean <a href=“<?php echo $_SERVER[‘HTTP_HOST’]; ?>”> ?

Not to mention that if you’re trying to make a generic package, HTTP_HOST will contain the domain name, but not any subfolders the script may be hiding in.

EG: I install your script into http://www.example.com/testscript/admin.php
<a href=“http://<?php echo $_SERVER[‘HTTP_HOST’]; ?>/admin.php”>Admin</a> is going to point to http://www.example.com/admin.php, not the URL expected.

I’m guessing you want a link to an absolute URL, am I right?

In that case it would be

<a href=“http://<?php echo $_SERVER[‘HTTP_HOST’]; ?>/admin.php”>Admin</a>

That is, you need to prepend “http://”, and there’s no need to let PHP handle “http://” and “/admin.php” as well :slight_smile:

Also remember that the value in $_SERVER[‘HTTP_HOST’] (if there is one!) is user input, just like any $_GET/$_POST values. You’ll need to properly sanitize/validate/escape its value.

i mean like that, that method is really works? for sure?

can I do like this
<a href=“<?php echo $_SERVER[‘HTTP_HOST’] . “/admin.php” ; ?>”>Admin</a>

thanks, it works