Redirect to previous page after login

  1. Save URL referer in login page
//For redirection after login
protected function save_referer(){
	$uri = $_SERVER['HTTP_REFERER'];
	//logg($uri);

	$pos = strpos($uri, BASE_URL);
	if($pos === false){
		return;
	}

	$uri = str_replace(BASE_URL, '', $uri);
	//logg($uri);
	$_SESSION['uri'] = $uri;
}

2. Check saved URI after login successfully and redirect

private function login_redirect(){
	if(isset($_SESSION['uri']) && $_SESSION['uri'] != false){
		$uri = $_SESSION['uri'];
		unset($_SESSION['uri']);
		redirect(BASE_URL . $uri);
	}else{
		redirect(BASE_URL . 'member/orders');
	}
}