PHP Script Switch Page to HTTPS

April 22, 2009

Here is a quick php script that you can add to the top of any page you want to be secure. Obviously, it requires you actually have an SSL Certificate all set up on your domain first.

1
2
3
4
5
6
7
8
9
10
<?php
if(empty($_SERVER['HTTPS']))
{
    // If not, redirect
    $newurl = 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    header("location: $newurl");
    exit();
}
 
?>

Tags: , ,

Was this Post helpful? Please consider a small contribution.

My Amazon.com Wish List
Pypal Tip


Leave a Reply

Asking for support? Win favor with a contribution for my time and expertise.