Reputation: 11
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! ;)
Upvotes: 0
Views: 110
Reputation: 10174
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'] : '';
Upvotes: 3