Redirect To Specific Page After Login And How To Access Returnurl From The Session


I have a page called "page 1". It has a area called "area 1"(please see the pic). In side area 1 there is a form. But the form shows only after log in. So I have give link to log in page(please see the pic). But after log in how should i redirect back to the page 1. I have searched for a solution and found it involves "returnUrl". So my first question is how and where should I set "returnUrl" to the above task.

And from below code I have notices return url and other data in $_SESSION. How can I access them.

A image of the result is attached with this.




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

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

				echo '<pre>' . print_r($_SESSION, true) . '</pre>';die; /////////  here




Any help is highly appreciated.

if you are unable to set returnUrl. in case if you definetly want to redirect the user to page1 you can change the Controller::redirect() to redirect the user to page1 like



Thanks for the replay. I can set as you said in siteController.php actionLogin method.

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


But then every time you login you will redirected to page 1. isn’t it? if a page 2 also a restricted page and when some one try to access page 2 he also will be redirect to page 1 after log in instead of redirecting to page 2.

I want like given below

  1. User goes to page 1.

  2. User cannot see the form in area 1.

  3. To see it he click on login link.

  4. User is in login page and he enter login details.

  5. User is redirected back to page 1 and he can see the form in area 1.

My problem is how to do number 5 task. Because he is now loged in he can see the form in area 1.

you are right nuwan. but redirecting the user to returnUrl will leads to redirect the user the previous page before login. if returnUrl doesnot works as expected there is another way also available do like this in controller



//your usual login code






and make the link in page1 for login like


Thanks Ahamed. It works.

you are welcome. :)