PHP 7 Script to Check if the Page Called From HTTP or HTTPS in Browser Full Project For Beginners

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments

 

Welcome folks today in this blog post we will be checking if the page called from http or https in browser using php 7. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to make an index.php file and copy paste the following code

READ  PHP 7 Script to Send SMS to Mobile Number Using Twilio SMS API Full Project For Beginners

 

 

index.php

 

 

 

<?php

if( (empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'off') || $_SERVER['SERVER_PORT'] != 443 )
{
  // Redirect to secure site
    header("HTTP/1.1 301 Moved Permanently"); 
    header("Location: https://www.your-domain.com"); 
    exit();
} else {
  // Do nothing when it is a secure site
}

?>

Leave a Reply