"too many redirects" with SSL redirect of CakePHP on heroku -


i'm getting [310] many redirects errors on heroku, when cake app tries redirect secure connection after forcing securitycomponent::requiresecure().

public function beforefilter() {     $this->security->blackholecallback = '_blackholecallback';     $this->security->requiresecure('login', 'register'); }  // ...  public function _blackholecallback($type) {     if ($type == 'secure') {         $this->redirect('https://' . env('server_name') . $this->here);     } } 

the problem cakephp , heroku handle secure connections differently.

cake's checking environmental variable 'https' true or false. heroku doesn't provide env, instead they're sending header 'x-forwarded-proto' 'https' value.

you have add new (or overwrite old 'ssl') detector , check header. did this:

class appcontroller extends controller {      public function beforefilter() {         $this->request->adddetector('ssl', array('callback' => function() {             return cakerequest::header('x-forwarded-proto') == 'https';         }));      // ...      } } 

hope who's having issue after me. got me several hours figure out.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -