How to check is URL https secure or not in php

URL https secured

In this unexpected tallying I am going to portion single heritage of php code to detect is server URL https secured or not, If the request was sent as soon as HTTPS you will have a added parameter in the $_SERVER which pay for all the warn roughly current request. So that you can easily check whether relationship safe or not by dispensation single descent of php code. And receive capture take leisure interest beyond https / http.

Following code will check is $_SERVER[HTTPS] set and upon or not If HTTPS is upon in addition to your current URL is safe and merged than https, Additionally check for fasten SSH state 443 too.

<?= ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) ? 'https' : 'http'; ?>

Above single origin of php code will gain you to profit whether current URL greater than https or http.

Also Read: How to get free SSL certificate and transfer your website from http to https

 

Leave a Reply