Remember Password Not Working After Customizing

In my site, the default controller action is Site/login. My remember password is working fine if the url is directly specified the controller action (http://localhost/projectname/site/index). But we need to customize the site url as http://localhost/projectname/ and we customized it. But after doing so the remember password is not working.I think it is because cookie is not getting there. How can I resolve it ?

Codes used

config/main




return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'ePlanMyTour',

                        'defaultController'=>'site/login',

                        'sourceLanguage'=>'en_us',

	// preloading 'log' component

	'preload'=>array('log'),

	// autoloading model and component classes

	'import'=>array(              

                        'application.models.*',

                   'application.controllers.*',

                        'application.components.*',

                           .

                           ............

                      

// uncomment the following to enable URLs in path-format

		

		'urlManager'=>array(

			'urlFormat'=>'path',                       

                                                                        'showScriptName'=>false,             

                                                                       'caseSensitive'=>true,

			'rules'=>array(

                                                                                       

				'<controller:\w+>/<id:\d+>'=>'<controller>/view',

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

			),

		),

		






.htacess




RewriteEngine on


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php




site/login




 public function actionIndex() {

        Yii::trace("The actionLogin() method is being requested", "application.controllers.SiteController");

        $model = new LoginForm;       

        // collect user input data

        if (isset($_POST['LoginForm'])) {

            $model->attributes = $_POST['LoginForm'];

            // validate user input and redirect to the previous page if valid

            if ($model->validate() && $model->login()) {

                $username = $_POST['LoginForm']['username'];

                $password = $_POST['LoginForm']['password'];

                $remember = $_POST['LoginForm']['rememberMe'];

                if ($remember == 1) {

                    setcookie('username', $username, time() + (60 * 60 * 24 * 30 ));

                    setcookie('password', $password, time() + (60 * 60 * 24 * 30));

                  

                } else {  

                    if (isset($_COOKIE['username']) && isset($_COOKIE['password'])) {

                        if ($_COOKIE['username'] == $username && $_COOKIE['password'] == $password) {

                          

                            unset($_COOKIE['username']);

                            setcookie('username', '', time() - 3600);

                            unset($_COOKIE['password']);

                            setcookie('password', '', time() - 3600);

                        }

                    }

                }                 

            }

        }

                                $this->render('index',array('model'=>$model));

    }



login.php




   <?php

		<div>

             if (isset($_COOKIE['username']) && isset($_COOKIE['password']))

               {

                    echo   $name = $_COOKIE['username'];

                    echo  $pwd = $_COOKIE['password'];

                    $check = true;

               }

            else

               {

                    $name = "";

                    $pwd = "";

                    $check = false;

               }

            echo $form->textField($model, 'username', array('placeholder' => 'Username', 'style' => 'width:185px; height:25px;', 'value' => $name));

    ?>

            <?php echo $form->error($model, 'username'); ?>

        </div>


        <div>


            <?php echo $form->passwordField($model, 'password', array('placeholder' => 'Password', 'style' => 'width:185px; height:25px;', 'value' => $pwd)) . "<br>"; ?>

            <?php echo $form->error($model, 'password') . "<br>"; ?>

            <?php echo $form->error($model, 'status'); ?>

		</div>


        <div>

            <?php echo "<br>" . CHtml::button('Sign In', array('submit' => array(''))); ?>

       </div> 




Thanks in advance

Why you are writing code to remember user. You should not do that. Yii has better functionality for this.

See any demo application like blog in Yii folder.

By the way your script is very poor. You’re sending password back to client with cookie.

Hmmmmmmm…