-3

I have design a template for many websites

however each site may use http or https

I try to use php to detect http or https

if I use HTTP_X_FORWARDED_PROTO to detect, is this correct?

Benjamin W
  • 2,658
  • 7
  • 26
  • 48
  • Possible duplicate of [How to find out if you're using HTTPS without $\_SERVER\['HTTPS'\]](https://stackoverflow.com/questions/1175096/how-to-find-out-if-youre-using-https-without-serverhttps) – Michał Szczech Jan 17 '18 at 06:39

1 Answers1

0

Try it. I hope it will work for you. If Any change in code, most welcome

<?php
    $uri = $_SERVER['REQUEST_URI'];
    echo $uri; // Outputs: URI
    echo "<br/>";

    $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";

   $url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
   echo $url; // Outputs: Full URL
   echo "<br/>";

   $query = $_SERVER['QUERY_STRING'];
   echo $query; // Outputs: Query String
?>
Ravi Shrimali
  • 111
  • 1
  • 9