A
A
andrey69rus2016-11-18 05:42:12
PHP
andrey69rus, 2016-11-18 05:42:12

How to implement a check for something via http or https if a person has a website open?

Good morning!
I had a question how to use php to check through which protocol the site is open on the client and display the message "https available" exactly the message if it is via http and not any forced redirects to https

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bkosun, 2016-11-18
@andrey69rus

The variable $_SERVER['HTTPS']takes a non-empty value if the request was made via the HTTPS protocol.
Note: Note that when using ISAPI with IIS, the value will be off if the request was not made over HTTPS.

www.php.net/reserved.variables.server
Hence:
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { 
// HTTPS
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question