Testing to see if webpage was accessed with HTTPS

Hi all.

Here is something I wasn’t able to find easily on the net. (Now that I know the answer, I’ll find it everywhere.)

For a project I’m working on, I needed to know if the site was accessed securely or not. (In part, so to only display the secure certificate verification icon/link only if the customer was on the secure part.)

Jeff T. (not sure if it’s the same Jeff that posts here) with support suggested I try SERVER_PROTOCOL, but that just returned http:/1.1 But with that, it led me to:


where SERVER_PORT returns 443 (SSL) or 80 (ordinary) as the case may be. In my case, I’m using PHP so I can just test the variable. ($SERVER_PORT).

I thought I’d post the answer here instead of replying to Jeff T. through the support line adding to the queue.

Thanks Jeff!


Yep, I see the date of two months ago on your post, but just had to let you know you saved me a lot of hassle. Your post let me stop pulling my hair out over how to somehow use htaccess for checking and redirecting. Thank you (and thanks, php- lol!)