0

This is the scenario: a user land on a page which redirects him at certain conditions with the following php lines

header("Location: /access/details/index.php");
die();

The problem is that the page /access/details/index.php should receive the referral URL correctly. I cannot insert an input tag because of the PHP redirect. What is the simpliest way to pass the URL to the redirect destination page, possibly without using other languages such javascript?

mark
  • 939
  • 2
  • 13
  • 36

1 Answers1

2

There is no way to tell the browser what URL to use for the referrer. Instead, you can pass the referrer as a get parameter in the redirect.

header("Location: /access/details/index.php?referrer=" . urlencode($_SERVER['HTTP_REFERER']));

Retrieve the previous referrer on your /access/details/index.php script by accessing the $_GET super global

$referrer = $_GET['referrer'];

Another option would be to skip the redirect altogether and do a forward. This keeps the current referrer intact.

include("/access/details/index.php");
die();
Preston S
  • 2,751
  • 24
  • 37
  • I'm using $_SERVER['HTTP_REFERER'] (with the second answer) in the details/index.php but it seems it doesn't work. I'm on localhost. Any suggestion? – mark Oct 09 '14 at 16:06
  • @mark You need to get it from the $_GET super global instead. See my update. – Preston S Oct 09 '14 at 16:07
  • @mark How did you get to the current script in your browser? If you simply typed in the URL in the nav bar there will be no referrer. – Preston S Oct 09 '14 at 16:15
  • Of corse, i'm accessing the /details/index.php through the 'include' like (redirect or whatever) i have inserted on the 'redirecting' page – mark Oct 09 '14 at 16:20
  • @mark But how did you get to the landing page that does the redirecting where you are writing this code? Add a debug print_r($_SERVER) and check that HTTP_REFERER has a value on this landing/redirect page. – Preston S Oct 09 '14 at 16:26