I have a PHP function:
function http_protocol()
{
return ($_SERVER['SERVER_PORT'] == 443) ? 'https' : 'http';
}
However, when the domain I am originating from is only HTTP, and I want to dynamically link to a domain that is HTTPS, the conditional returns http.
So, my thought is that I could check to see if the site responds to an HTTPS request, and if so, then return https, else return http.
I was thinking it could be doable using the @get_headers array, and check to see if the [0] value had HTTPS, but I wasn't able to confirm if an HTTPS header existed (e.g. HTTPS/1.1).
I was following this question: How can I check if a URL exists via PHP?, except I would be checking for HTTPS.
Is my logic flow correct, or is there something I'm missing?
Edit: in the particular example, I would only be checking sites I have control over. So I know beforehand if content is served over HTTPS or not.