php restrict https

Post Reply
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

php restrict https

Post by Saman » Wed Aug 04, 2010 7:25 pm

There are some situation that you need to only allow access to your php ,pages only through SSL. You may use the following code at the beginning of the page. This will reload the page with https.

Code: Select all

if($_SERVER["HTTPS"] != "on"){
    header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
    exit();
} 
Post Reply

Return to “PHP & MySQL”