DZone: Your Personal Tech Universe PHP Zone
Published on PHP Zone (http://php.dzone.com)
Force A Secure Page Using PHP
By davidwalsh
Created 2008/03/15 - 10:11am

Force A Secure Page Using PHP

Many pages, most often pages with forms or pages that serve personal information, require the need to be served over a secure connection. Even recreational internet users have gotten accustomed to looking for "lock" icon within their browser before inputting data into a web form. For the benefit of the business and its website visitors, it's important to ensure that a form page be secured.

To ensure that you page is served over a secure connection, you must first acquire a security certificate. Popular SSL certificate providers include Verisign, Thawte, and GoDaddy (whom I prefer). Once your SSL certificate has been installed on the server, you may add the following code snipped at the top of any page you would like secured:

The PHP Code

//force redirect to secure page
if($_SERVER['SERVER_PORT'] != '443') { header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); exit(); }

The above code forces the script to run on secure port 443 as opposed to port 80. Thus, the page is served securely.

Reference: 
Force A Secure Page Using PHP [1]

Source URL: http://php.dzone.com/news/force-secure-page-using-php

Links:
[1] http://davidwalsh.name/force-secure-page-php