PHP Determine host safely and reliable

32 Views Asked by At

For my script, which relies on the host url, I need to determine the host and whether it's connection over HTTP protocol or HTTPS protocol.

for instance, if I connect to http://example.com, I would like to retrieve http and example.com

I can of course use the $_SERVER variables. However, I have read on the internet that they are easily changeable by the client. Therefore, they 'could' break my script. So, $_SERVER['HTTP_HOST'], $_SERVER['SERVER_NAME'], etc become unreliable I guess?

Is there any better option to tackle this issue instead of checking both $_SERVER variables for the same value, which is still unreliable?

Thanks for your answers

1

There are 1 best solutions below

1
lessan On

you can simply make a config.php file where you define some constants that you need and then just include it anywhere you need them. Or maybe i misunderstood, but i think this is what you want