Getting protocol from the URL in controller Getting protocol from the URL in controller symfony symfony

Getting protocol from the URL in controller


You can use this in your controller :

$scheme = $this->getRequest()->getScheme();

Otherwise, here is a code allowing you to know all the values ​​returned by the server:

 foreach ($_SERVER as $key => $value) {      echo $key.' => '.$value.'<br>';    }


To check if request is https use:

$request->isSecure()

Check doc for more info


Pass request to the controller, get the scheme, or schema and host:

function doSomething(Request $request){       echo $request->getScheme();    echo $request->getSchemeAndHttpHost();}