How to get URL address of redirected page?
Moderator: General Moderators
-
surfinglight
- Forum Newbie
- Posts: 9
- Joined: Wed May 04, 2005 10:04 pm
How to get URL address of redirected page?
Hello,
I have written codes which read url from a table and redirect to the address.
For example, when id number 3274 is passed,
http://www.sample.com/process?id=3274
This will search the relevant url address from a table(let's say, 3274 is http://www.yahoo.com),
and redirect a user to the address.
Therefore, the user who runs "http://www.sample.com/process?id=3274" will be redirected to
http://www.yahoo.com
My question is how do I code to retireve that URL addres, "http://www.yahoo.com" when coding.
I mean assuming that I cannot refer to the table.
So, I would like to know how to code to retrieve the url address after redirection is occured(it will be "http://www.yahoo.com" from the above sample), assuming that I only know the url address which will redirect itself to other address(it will be "http://www.sample.com/process?id=3274" from the above sample).
Is there a Php function for this?
I would really appreciate if some one can help on this.
Many thanks in advance.
I have written codes which read url from a table and redirect to the address.
For example, when id number 3274 is passed,
http://www.sample.com/process?id=3274
This will search the relevant url address from a table(let's say, 3274 is http://www.yahoo.com),
and redirect a user to the address.
Therefore, the user who runs "http://www.sample.com/process?id=3274" will be redirected to
http://www.yahoo.com
My question is how do I code to retireve that URL addres, "http://www.yahoo.com" when coding.
I mean assuming that I cannot refer to the table.
So, I would like to know how to code to retrieve the url address after redirection is occured(it will be "http://www.yahoo.com" from the above sample), assuming that I only know the url address which will redirect itself to other address(it will be "http://www.sample.com/process?id=3274" from the above sample).
Is there a Php function for this?
I would really appreciate if some one can help on this.
Many thanks in advance.
You could fe: use scriptable browser:
And test if there is a Location header present...
Code: Select all
require_once('simpletest/browser.php');
$browser = &new SimpleBrowser();
$browser->setMaximumRedirects(0);
$browser->get('http://example.com/link=1234');
$browser->getHeaders();- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you want to know what address a url redirects to?
A HTTP redirect uses the page headers. In PHP 5 get_headers() can be used (cURL in older versions, which is quite a bit more complicated, but works similarly). You'll also need to check the returned page code for meta refresh (easy to detect) and possibly a javascript redirect (can be quite hard to detect) using regular expressions..
A HTTP redirect uses the page headers. In PHP 5 get_headers() can be used (cURL in older versions, which is quite a bit more complicated, but works similarly). You'll also need to check the returned page code for meta refresh (easy to detect) and possibly a javascript redirect (can be quite hard to detect) using regular expressions..
-
surfinglight
- Forum Newbie
- Posts: 9
- Joined: Wed May 04, 2005 10:04 pm
timvw wrote:You could fe: use scriptable browser:
And test if there is a Location header present...Code: Select all
require_once('simpletest/browser.php'); $browser = &new SimpleBrowser(); $browser->setMaximumRedirects(0); $browser->get('http://example.com/link=1234'); $browser->getHeaders();
Thanks for your reply.
I have a question.
Where can I find the following file please?
'simpletest/browser.php'
feyd | it helps to have BBCode and Smilies enabled for the tags to work..
-
surfinglight
- Forum Newbie
- Posts: 9
- Joined: Wed May 04, 2005 10:04 pm
Thanks
Hi,
Thank you very much for your swift reply.
Would there be any other way to implement it without using third party codes?
Many thanks.
Thank you very much for your swift reply.
Would there be any other way to implement it without using third party codes?
Many thanks.
-
surfinglight
- Forum Newbie
- Posts: 9
- Joined: Wed May 04, 2005 10:04 pm
[quote="feyd"]read my post..[/quote]
Hi,
Thanks for your kind help. Really helpful.
Since my current hosting does not support Php 5, I tried it as follows:
$test = "http://www.sample.com/process?id=3274 ";
$ch = curl_init($test);
$txt=curl_exec($ch);
echo $txt;
This outputs a message to click on an anchored text shown to redirect.
I can code to retireve the redirected url address from $txt.
But this is an extra coding.
Any other better way afterwards? I mean, without searching and retrieving from the $txt value.
Would there be any one call function to get the redirected address?
Many thanks to you all.
Hi,
Thanks for your kind help. Really helpful.
Since my current hosting does not support Php 5, I tried it as follows:
$test = "http://www.sample.com/process?id=3274 ";
$ch = curl_init($test);
$txt=curl_exec($ch);
echo $txt;
This outputs a message to click on an anchored text shown to redirect.
I can code to retireve the redirected url address from $txt.
But this is an extra coding.
Any other better way afterwards? I mean, without searching and retrieving from the $txt value.
Would there be any one call function to get the redirected address?
Many thanks to you all.