Forum Moderators: coopster

Message Too Old, No Replies

Tricky FOPEN question

         

rfontaine

1:30 am on Jan 29, 2005 (gmt 0)

10+ Year Member



I have been playing around with something like this:

$ft = @fopen("http://www.example.com", "r") or die( "Didn't get it!");

It works, but what I want to know is sometimes "http://www.example.com" may actually be redirected to some other site. The FOPEN function sucessfully reads the site content when it is redirected and I would like to obtain the url it is redirected to and put it into a variable.

For example, if [example.com...] redirects to [xyz.com...] is there a way to find out and store it like $redirected_url = 'http://www.example2.com'?

Any ideas appreciated.

[edited by: jatar_k at 8:00 pm (utc) on Feb. 1, 2005]

Lord Majestic

1:36 am on Jan 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



is there a way to find out and store it like $redirected_url = 'http://www.xyz.com'?

Redirection is typically done using "Location" header, you will need to analyse headers for that, typically response code will be 301 (Moved permanently). Note that this is not an unusual scenario when you request directory but you did not have '/' at the end: www.example.com/somedir would cause redirect to www.example.com/somedir/

rfontaine

1:46 am on Jan 29, 2005 (gmt 0)

10+ Year Member



Thank you very much Lord Majestic...

Is there any way to capture that value using PHP (not version 5)?

I looked into get_headers but, alas, it is a version 5 function.

rfontaine

10:08 am on Jan 29, 2005 (gmt 0)

10+ Year Member



anybody?

mincklerstraat

10:18 am on Jan 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



have you had a look at [pear.php.net...]