tags:

views:

357

answers:

3

I would like to use a secure SSL login on my website! I have not used SSL before, so I am looking for some good reading. Can anyone tell me where I can find some sample code of SSL snippets or page code. (Not too technical)

  • I do have a static IP
  • My host is set-up to handle SSL Pages.

Interested in: Basic page code. / Tree structure. / Other

Paul

+1  A: 

My first thought would be to simply call a function to redirect to the https: version of the current page when you need to be secure.

Some code like this:

if($requireSSL && $_SERVER['SERVER_PORT'] != 443) 
{
   header("HTTP/1.1 301 Moved Permanently");
   header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
   exit();
}

Reference

Graphain
+1  A: 

If you've an SSL enabled host, writing a login is not different to writing one without SSL - all the encryption happens at a lower layer of the protocol stack, so by the time your PHP sees the request, it's already decrypted. Similarly, your script outputs are encrypted by the HTTP server before onward transmission back to the user.

Paul Dixon
A: 

SSL happens before the request ever reaches PHP. The only impact on your PHP would be in the self-facing links you're publishing, which you'd want to switch from http://... to https://... There's a $_SERVER['HTTPS'] variable you could use to trigger this change if you'll be accepting both SSL and non-SSL connections. But if you're moving everything to SSL, you'll want to move all your links once rather than having it check on each request.

Scott Reynen