For instance, using this code:
$curl = curl_init();
curl_setopt_array( $curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => "$url" ) );
curl_exec( $curl );
$header = curl_getinfo( $curl, CURLINFO_HTTP_CODE );
curl_close( $curl );
$url = "http://upenn.edu"
will not work, while $url = "http://www.upenn.edu"
will work.
Without the www.
the response code I get is 0
, whereas with the www.
it is 200
.
If I were to use PHP get_headers("http://upenn.edu")
, I would get two errors:
Warning: get_headers() [function.get-headers]: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
and
Warning: get_headers(http://upenn.edu) [function.get-headers]: failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
However, when I use the exact same code, http://google.com
will work (as well as the expected http://www.google.com
.)
Then, for a website such as http://www.dogpile.com
, the www.
part included returns a response code of 0
whereas without the www.
, I get a 302
.
Why is this? and is there a better method to use in order to ensure reliable results (i.e., where a www.
is not present, yet the response code is still returned?)
I am new to using cURL and dealing with headers and response codes, so any help is appreciated. Thank you.