Page 1 of 1

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

Posted: Sat Apr 05, 2008 9:32 pm
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?

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

Posted: Sat Apr 05, 2008 11:51 pm
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 !

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

Posted: Sun Apr 06, 2008 2:31 am
by Chris Corbyn
Sounds like the server is attempting to block clients it doesn't recognise as web browsers.