Jump to content

file_get_contents() Functionality...?


cyfer65

Recommended Posts

How come this will work...

<?phpecho file_get_contents('http://whatismyip.org/');?>

But this wont..?

<?phpecho file_get_contents('http://tinyurl.com/yardhc');?>

the tinyurl just forwards to http://whatismyip.org/why doesn't it follow through to the forwarded site to get its contents..?What else can i do to make it work using the tinyurl..?

Link to comment
Share on other sites

How come this will work...
<?phpecho file_get_contents('http://whatismyip.org/');?>

But this wont..?

<?phpecho file_get_contents('http://tinyurl.com/yardhc');?>

the tinyurl just forwards to http://whatismyip.org/why doesn't it follow through to the forwarded site to get its contents..?What else can i do to make it work using the tinyurl..?

That's because what tinyurl does is send a location header to the client which contains the URL that the client must redirec to. You would need to use cURL to read the response header and have your program use file_get_contents on the URL that's found in that header.
Link to comment
Share on other sites

Basically, file_get_contents() doesn't follow the redirect, like more advanced libraries such as cURL can.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...