1

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");
Adam Smith
  • 145
  • 1
  • 1
  • 6

4 Answers4

4

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

dabide
  • 996
  • 1
  • 6
  • 18
1
header('Location: ' . $_SERVER['HTTP_REFERER']);
exit;

Source: Back to previous page with header( "Location: " ); in PHP

Community
  • 1
  • 1
Farid Movsumov
  • 12,350
  • 8
  • 71
  • 97
0

Found that the following does work:

header("location:javascript://history.go(-1)");

(via Back to previous page with header( "Location: " ); in PHP)

Community
  • 1
  • 1
ejazz
  • 2,458
  • 1
  • 19
  • 29
-2
if(count($user)==0){
    echo "<script>JavaScript:history.back()</script>";
}
Murat SAÇ
  • 396
  • 1
  • 3
  • 13