0

I need help on redirect of php scripts. The problem is: I have a page for example www.domain.com/redirect.php?id=34 that redirects to another page, domain2.com/product.php?id=2. I need to create a script that allow me to know the URL of the redirection (domain2.com/product.php?id=2) just by accessing the redirector (www.domain.com/redirect.php?id=34). Anyone have a an idea? tanks! ;)

1
  • url of redirection is obviously known in the redirector script;), make the question clearer please Commented Jul 19, 2010 at 20:23

1 Answer 1

3

One solution is opening socket to www.domain.com, sending request, waiting reply and reading/parsing HTTP "Location: ...." header.

Or if you are using PHP 5.0 or above you can take advantage of get_headers().

$url       = 'http://www.google.com/';
$headers   = get_headers($url, 1);
$redirect  = isset($headers['Location']) ? $headers['Location'] : '';
Sign up to request clarification or add additional context in comments.

Comments

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.