0

UPDATE

Let's say, my users went to this page:

https://www.abc.com/mypage.php

The response headers for that page are:

    Content-Length  28
    Date    XXXX
    Location    https://abc.com/error.php?target=https%3A%2F%2Fabc.com%2Fmypage.php&
errorReason=Go+To+this+Url
    Server  MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)

That means the page is redirecting to https://www.abc.com/errorpage.php with the querystring params in the Location header.

Now on errorpage.php, instead of using $_GET to get the querystring parameters, I wanted to get the Location header, parse out the parameters and print them.

The downside to doing $_GET is, my users can enter any crap in the querystring and my errorpage.php will print it. So i wanted to avoid that by detecting the Location header.

Is there any way to get the Location header from the redirect? I am not seeing using getallheaders() or any other PHP function.

Thanks

5
  • Maybe you might want to elaborate a bit on usage context, instead of only vaguely alluding to the Location header. (Except if the first three guessed answers were useful of course). Curl request? Within the target page? (Hint: then it becomes a GET parameter). What have you tried? What's the actual purpose of pageredirect.php? Commented Aug 15, 2014 at 20:57
  • changed the description my issue. Please revire. Commented Aug 15, 2014 at 21:12
  • Does your Apache version support apache_request_headers()? Commented Aug 15, 2014 at 21:17
  • 2
    The Location: header is sent to the HTTP client. Outgoing direction. The browser then requests the mentioned page. In that incoming HTTP request, there will be no Location header. You cannot access it. Commented Aug 15, 2014 at 21:17
  • Is there a way to figure out if the browser request was a redirect or a regular request? Commented Aug 15, 2014 at 21:22

4 Answers 4

1

I am not sure if you are looking for something other than a simple $_GET?

$target = $_GET['target'];

$errorReason = $_GET['errorReason'];
Sign up to request clarification or add additional context in comments.

1 Comment

I am looking for getting the "location" header and not just plain $_GET.. I believe that the location header is only available on a redirect
1

if you are executing the script:

$target = $_GET['target']; $errorReason = $_GET['errorReason'];

if all you have is the URL:

$url = "https://abc.com/pageredirect.php?target=https%3A%2F%2Fabc.com%2Fredirecttopage.php&errorReason=Simple+redirect";
$urlObj = parse_url($url);
$getVars = $urlObj['query'];
parse_str($getVars);
echo "Target: ".$target." and errorReason: ".$errorReason;

Comments

0

You can get those URL parameters using the $_GET array:

$_GET['target'];

$_GET['errorReason'];

Comments

0

The parameters are in the $_GET variable

$_GET['target'];

$_GET['errorReason'];

1 Comment

How do I get the entire location header?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.