if (!isset($_COOKIE['prev_addr'])){
setcookie("prev_addr",$_SERVER["HTTP_REFERER"],time()+3600,"/");
}
global $USER;
if ($USER->IsAuthorized()) {
$temp = $_COOKIE['prev_addr'];
setcookie("prev_addr","",time()-3600,"/");
//unset($_COOKIE['prev_addr']);
LocalRedirect($temp);
}