PHP and SSL Certificates

Wonder if anyone can help…
I’m having a lot of trouble finding any reference material relating to the installation of an SSL certifcate and PHP coding to use SSL certificates.

I’ve created a website in a development enviornment and it’s built using PHP. The entire site has all been built using knowledge gained from Kevin Yank’s BYODDW and the Sitepoint PHP Live course.

Now that I want to take personal details from visitors to my site (names, addresses, contact numbers etc) I would like to use an SSL certificate.

I’m afraid I know absoultely nothing about installing a certificate and what changes I need to make to my PHP code in order to use SSL functionality.

Does anyone know of a good reference manual / book / guide which could provide some answers and examples of PHP coding ? Anything that comes close to Sitepoint standard documentation would be wonderful.

Many Thanks,

There is very little that you need to do differently with your PHP to work under a secure environment. Once you have the certificate installed you could request http://example.com/myscript.php and get the page unencrypted, or request https://example.com/myscript.php and get exactly the same thing with the secure connection between browser and server. The PHP need know nothing about it.

The only thing you may want to do is use PHP to force access to certain pages via SSL.
For example a login page might check that the server port is 443 (secure) and not display the login form, or redirect to the secure version if requested at the non secure URL.
Or you might use a .htaccess file to force access to certain sections of your site via https:


//Redirect if script not accessed securely
if($_SERVER['SERVER_PORT']	!= 443) {
  header("Location: https://example.com/myscript.php");
  exit;
}

PHP is also not involved with installing the SSL. Usually you’d contact your web host and ask them to do it.

Excellent.
Thank you very much.