class HttpsFilter extends CFilter { protected function preFilter($filterChain) { if ( !Yii::app()->getRequest()->isSecureConnection ) { # Redirect to the secure version of the page. $url = 'https://' . Yii::app()->getRequest()->serverName . Yii::app()->getRequest()->requestUri; Yii::app()->request->redirect($url); return false; } return true; } }
The problem is that once the filter is called, the secure connection stays activated, when what I want is have https just in certain pages (actions) of my site.
So what I have done is copy the filter to make a HttpFilter.php
class HttpFilter extends CFilter { protected function preFilter($filterChain) { if ( Yii::app()->getRequest()->isSecureConnection ) { $url = 'http://' . Yii::app()->getRequest()->serverName . Yii::app()->getRequest()->requestUri; Yii::app()->request->redirect($url); return false; } return true; } }
And I add the filter in the controller for the actions where I don't want https:
public function filters() { return array( 'https +new, payment', 'http +index, complete' ); }
This works, but I'm not sure if it's a good approach. What do you think?
Thanks, Pablo.