Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. function redirect_ssl()
  2. {
  3.     $isSecure = false;
  4.     if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
  5.         $isSecure = true;
  6.     } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
  7.         $isSecure = true;
  8.     }
  9.     $REQUEST_PROTOCOL = $isSecure ? 'https' : 'http';
  10.  
  11.     if ($REQUEST_PROTOCOL == "http") {
  12.         $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  13.         header('HTTP/1.1 301 Moved Permanently');
  14.         header('Location: ' . $redirect);
  15.         exit();
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement