Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting protocol from the URL in controller

Tags:

symfony

I Googled it but maybe my search keywords are useless so how can I get URL protocol in controller? IS it http:// or https://

http://whatever.com/app_dev.php/welcome

//I need to echo http:// protocol here
echo $request->getHost(); //echos whatever.com
echo $request->getBaseUrl(); //echos app_dev.php/
like image 488
BentCoder Avatar asked Jul 05 '14 10:07

BentCoder


2 Answers

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>';
    }
like image 55
user3687941 Avatar answered Sep 17 '22 18:09

user3687941


To check if request is https use:

$request->isSecure()

Check doc for more info

like image 40
Tomasz Madeyski Avatar answered Sep 21 '22 18:09

Tomasz Madeyski