how to use php function: file_get_contents() for url?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
earthsci
Forum Newbie
Posts: 1
Joined: Sat Apr 05, 2008 9:29 pm

how to use php function: file_get_contents() for url?

Post by earthsci »

I try to use
php function
"file_get_contents($url)"
to obtain the content of
a remote page ($url) such as following address:
http://www.gsajournals.org/perlserv/?re ... /G24340A.1
or
http://www.blackwell-synergy.com/doi/ab ... .tb00101.x

but it returns nothing

most web pages work fine, but cannot obtain any content from the above
urls,

any other method to do this?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Re: how to use php function: file_get_contents() for url?

Post by anjanesh »

Code: Select all

C:\>php -r "print_r(get_headers('http://www.gsajournals.org/perlserv/?request=get-pdf&doi=10.1130/G24340A.1', TRUE));"
Array
(
    [0] => HTTP/1.1 302 Found
    [Date] => Array
        (
            [0] => Sun, 06 Apr 2008 04:48:55 GMT
            [1] => Sun, 06 Apr 2008 04:48:56 GMT
            [2] => Sun, 06 Apr 2008 04:48:58 GMT
        )
 
    [Server] => Array
        (
            [0] => Apache
            [1] => Apache
            [2] => Apache
        )
 
    [Set-Cookie] => Array
        (
            [0] => ENABLED=true; path=/; expires=Wed, 01-Apr-2009 04:48:55 GMT
            [1] => SESSID=e963d426dd9c6f8813493f6ed664114d; path=/; expires=Sun, 06-Apr-2008 05:18:56 GMT
        )
 
    [Location] => Array
        (
            [0] => http://www.gsajournals.org/perlserv/?re ... 40A.1&ct=1
            [1] => http://www.gsajournals.org/perlserv/?re ... 6ed664114d
        )
 
    [Content-Length] => Array
        (
            [0] => 340
            [1] => 384
            [2] => 18958
        )
 
    [Connection] => Array
        (
            [0] => close
            [1] => close
        )
 
    [Content-Type] => Array
        (
            [0] => text/html; charset=iso-8859-1
            [1] => text/html; charset=iso-8859-1
            [2] => text/html; charset=utf-8
        )
 
    [1] => HTTP/1.1 302 Found
    [2] => HTTP/1.1 403 Access Denied
)
 
C:\>
Weird that its giving 3 HTTP status codes & 2-3 of every other field !
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: how to use php function: file_get_contents() for url?

Post by Chris Corbyn »

Sounds like the server is attempting to block clients it doesn't recognise as web browsers.
Post Reply