How to get referer from access deny page

Hi all,

I have a problem with the $_SERVER[‘HTTP_REFERER’], below was the condition:

  1. User Guess and accees a page that need authorize ( login user ), so it will redirect user to login page

  2. at the login page, i would like to get the previous url ( but fail ) and redirect back to this page after i success login.

can anyone give me some idea how to sold this problem? $_SERVER[‘HTTP_REFERER’] will return nothing if in this condition, it will only return the referer url if i come from a page than already allow to access.

There’s a built-in solution: Yii::app()->user->returnUrl