I have the following code to redirect user to login page if they haven't log in. But I want to redirect them page to the page they came from after the login, any ideas how to do it?
if(count($user)==0) redirect_page("/login.php");
I have the following code to redirect user to login page if they haven't log in. But I want to redirect them page to the page they came from after the login, any ideas how to do it?
if(count($user)==0) redirect_page("/login.php");
You could just add the path to the page they came from to the query string, like this:
/login.php?returnUri=/the/page/they/came/from.php
header('Location: ' . $_SERVER['HTTP_REFERER']);
exit;
Source: Back to previous page with header( "Location: " ); in PHP
Found that the following does work:
header("location:javascript://history.go(-1)");
(via Back to previous page with header( "Location: " ); in PHP)