5

In Symfony 2, I want to check if the current request is secure (SSL) or not, and I know that we can do that with pure php such as checking the $_SERVER['https']. However, I wonder if there is any Symfony method/helper that already helps us to determine that?

mr1031011
  • 3,574
  • 5
  • 42
  • 59

1 Answers1

7

Symfony\Component\HttpFoundation\Request has isSecure method. You can use it in your controller in the following way:

if ($this->getRequest()->isSecure()) {
    // ...
}
Molecular Man
  • 22,277
  • 3
  • 72
  • 89
  • 2
    In my case this function was not working correctly, so I used the one described at http://stackoverflow.com/questions/1175096/how-to-find-out-if-you-are-using-https-without-serverhttps – Tomasz Kuter Feb 20 '15 at 19:11