Which One Does Linking To Self Page With Absolute Url?

Hello People,

I need some assistance here.
How do you do linking to self page that echoes full url ? Absolute url with scheme, host, path ?

I made these notes. Which one you suggest for me, can you tell me now ?

echo $file_path = $_SERVER['PHP_SELF'] .'/find/'; echo '<br>';
echo $file_path = "{$_SERVER['PHP_SELF']}/find/"; echo '<br>';
//RELATIVE URL:
echo $file = basename(__FILE__,'');  echo '<br>';
//ABSOLUTE URL:
//https://stackoverflow.com/questions/6768793/REQUEST-the-full-url-in-php
echo "https://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}"; echo '<br>';
echo $actual_link = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; echo 

I, waiting to hear from you pros.

Referring to your stackoverflow one (number 3) I think you missed the most accepted answer which is probably the one I would go with…

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

Or if you want to account for either http/https…

$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

But take heed of the note on security with this. Whenever you build links like this, you want to also validate the end result. If you can, I would just store the HOST as a variable since that should always be the same for your site. As for REQUEST_URI just make sure that it matches an actual document you want to be shown. Make sure it is not containing anything it shouldn’t like pointing at system files or files with any secrets etc.

P.S. I honestly try to avoid building any links with user supplied data. I prefer to always build my own links using data that comes from the system or that I have set in a variable that can’t be tampered with.

Thread closed as the OP is banned.