2

How to get the request page name or uri from which the source page is loaded.

Explanation below:

index.php

<?php
  header('Location:target.php');
?>

target.php

<?php
  // How to check here if the redirection has happened from index.php
?>
Netorica
  • 18,523
  • 17
  • 73
  • 108
Shabeer Mothi
  • 137
  • 1
  • 13

2 Answers2

4

you can use the code below

echo $_SERVER["HTTP_REFERER"];

but to make sure you can get really the exact origin of your page you can store the current url to a session before doing a redirection and read it to the next page.

in the origin page

$_SESSION['origin'] = $_SERVER['REQUEST_URI'];

then in next page

echo $_SESSION['origin'];
Netorica
  • 18,523
  • 17
  • 73
  • 108
2

you can use $_SERVER["HTTP_REFERER"] but it can't be trusted. Some browsers will have the correct value other will have null value.

Here is what php manual says about it:

'HTTP_REFERER' The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

In short, I don't think you can get a reliable solution for what you want.

DoubleM
  • 454
  • 1
  • 3
  • 11
  • Thanks a ton for your response. It was helpful. But i think the solution to store it in database gives my question a solution. Appreciate your help. – Shabeer Mothi Apr 12 '14 at 16:05