Zend Framework 1 force HTTPS

How to force HTTPS to use Zend Framework 1 Zend_View_Helper_Urland the request object?

I have this, but I'm looking for a way to ZF1 without matching the _SERVER variables ...

if (!$this->getRequest()->isSecure()) {
    $this->redirect(
        'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']
    );
}

Please do not offer a solution .htaccess. Too many questions asked by Zend code with mod_rewrite suggestions.

I know that you can pass optionsURL / redirect to the helper, but I'm not sure how this is done.

pseudo code:

$this->redirect(array('useHttps' => true), $this->getRequest()->getRequestUri());
+4
source share
2 answers

Try serverUrl () helper

// Current server URL in the example is: http://www.example.com/foo.html

echo $this->serverUrl();
// Output: http://www.example.com

echo $this->serverUrl(true);
// Output: http://www.example.com/foo.html

echo $this->serverUrl('/foo/bar');
// Output: http://www.example.com/foo/bar

echo $this->serverUrl()->getHost();
// Output: www.example.com

echo $this->serverUrl()->getScheme();
// Output: http

$this->serverUrl()->setHost('www.foo.com');
$this->serverUrl()->setScheme('https');
echo $this->serverUrl();
// Output: https://www.foo.com

http://framework.zend.com/manual/1.12/en/zend.view.helpers.html

+2
source
    protected function _initForceSSL() {
      if($_SERVER['SERVER_PORT'] != '443') {
         header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
         exit();
       }
    }

Put this function in your bootstrap file

+2

All Articles