Reputation: 49
I want to use https for my CakePHP application.
I found some articles explain how to force https in CakePHP ( http://blog.andolasoft.com/2013/07/ssl-authentication-using-security-component-in-cakephp.html )
But the problem is I'm using load balancer (AWS), so I faced with the problem if I use redirect (redirect loop).
Would anyone have experience with this issue?
How to force https in CakePHP without redirect from http ?
Thanks so much.
Upvotes: 1
Views: 3240
Reputation: 561
I use CakePHP 2 on server without https, but with activated cloudflare (with https). So CloudFlare give me https to the end user. This is what I have added to my /app/webroot/index.php to make it work:
function isSSL(){
if( !empty( $_SERVER['https'] ) )
return true;
if( !empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' )
return true;
return false;
}
define('IS_IN_PRODUCTION', 1);
if( !isSSL() && IS_IN_PRODUCTION > 0){
header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
exit();
}
I hope this can help!
Upvotes: 2