In my new application API, I have to check the request from the third party URL's should be in https. If it is not https, I have to return the message as "connection is not secure'. Can anyone help me?
Daniel Tran's answer is correct just for information HTTPS type requests have an extra field HTTPS on requests. Sometimes this field can be equal to off too but nothing else.
so you can just write a code like
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
doSomething();
}
Laravel Request Class also inherited something totally similar from symphony. Which You can find under;
vendor/symfony/http-foundatiton/Request.php
public function isSecure()
{
if ($this->isFromTrustedProxy() && self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && $proto = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO])) {
return in_array(strtolower(current(explode(',', $proto))), array('https', 'on', 'ssl', '1'));
}
$https = $this->server->get('HTTPS');
return !empty($https) && 'off' !== strtolower($https);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With