-1

i have been trying to force my page to a HTTPS address, but it does not work, but when i echo the $url it gives the desired address with https

code

<?php 
if (!isset($_SERVER['HTTPS']) || !$_SERVER['HTTPS']) {
    $url = 'https://' . $_SERVER['HTTP_HOST']
    . $_SERVER['REQUEST_URI'];

    header('Location: ' . $url);

}
?>

still the page loads with http protocol, can anybody help me to get it to a https page

Sho Gum Lew
  • 329
  • 1
  • 5
  • 17
  • 1
    Define "does not work". What actually happens? What do you see if you monitor the request in the Net tab of your browser's developer tools? Do you see the request for the HTTP version being made? Does it get a response? Does the response include the location header? Do you see the request for the HTTPS version? Does it get a response? Is the response correct? What do the server's log files say? What if you turn PHP error reporting up as high as possible? – Quentin Jan 20 '15 at 09:25
  • does not work means.. the page loads with http protocol, thats what i can clearly see – Sho Gum Lew Jan 20 '15 at 09:30
  • Does other PHP work if you put it on the page? – Quentin Jan 20 '15 at 09:31
  • yes other php stuff works fine – Sho Gum Lew Jan 20 '15 at 09:37
  • What do the server's log files say? What if you turn PHP error reporting up as high as possible? – Quentin Jan 20 '15 at 09:37
  • how to turn on php error reporting – Sho Gum Lew Jan 20 '15 at 09:49
  • [Google](https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&es_th=1&ie=UTF-8#safe=off&q=php%20error%20reporting) says [`error_reporting(E_ALL)`](http://php.net/manual/en/function.error-reporting.php) – Quentin Jan 20 '15 at 09:59

1 Answers1

-1

It could be that you're running the code on your local host instead of an actual live server. Just tested this an it redirected me as it should

Sam Nakale
  • 59
  • 2