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!

$_SERVER.HTTPS

Is a non-empty value if the script was queried through the HTTPS protocol.

Thanks @mebeingken!

So can I test that in an if condition then?

Like this?

{{$_SERVER['HTTPS']}}

Or like this?

{{$_SERVER.HTTPS}}

If you put HTTPS in the Input (formerly Globals) it will handle the syntax for you. On the server, it will end up being dot notation.

I mispoke, it actually isn’t a boolean.

“Set to a non-empty value if the script was queried through the HTTPS protocol.”

My test returns “on” with https

Thanks for all your help with this Ken!

I’m using it with my production site on AWS Elastic Beanstalk with a load balancer… and I get null on my localhost and on the production site.

I’ve asked AWS for help by they don’t seen so sure either… so for now I’ve just done a detection of the subdomain part of the url and worked with that.

Happy days! :slight_smile:

I think that might be the case if your load balancer is not communicating securely back to the servers. For example I just setup a site on Amazon Lightsail, using their default CDN. By default the communication from the CDN (perhaps also load balancer) is http even if the channel from the client to the CDN is secure. I suppose that is fine if the channel is otherwise secured internally. So then your code runs on the server and sees an http request. Might have to look at passing proxy headers and other such stuff.

Haven’t done this setup myself, so I’m just throwin’ out ideas.