Skip to main content
  1. Posts/

Forcing HTTPS with PHP

·22 words·1 min·

To force HTTPS with a PHP script, just put this snippet near the top:

if ($_SERVER['SERVER_PORT'] != 443) {
header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
}