Calling a PHP Guru - What $_SERVER[] Variables Will Give The Root Of My App?

I want to assign a value in a server action that is the root of my app’s url address with the correct use of http or https… so for my production server it should return

https://app.my-app-domain.com

But for my local test server it should return

http://localhost

I have been using the following code:

$_SERVER['SERVER_PROTOCOL'].split("/")[0]+'://'+$_SERVER['HTTP_HOST']

But the $_SERVER['SERVER_PROTOCOL'] part always returns 'http'…!

If anyone knows the answer I’d be very grateful!

Community Page
Last updated: