Jump to content

Using cURL to verify existence of URL always returns 302 Found / OpenDNS


Helmet

Recommended Posts

Hi, DNS is not my strong point, but I don't know why I would be having this problem anyway. I want to use cURL to check URL's entered by my users to make sure they exist. Testing this, if I enter a garbage URL like "asdfsfdfsfdf ", I always get the following response:

 

HTTP/1.0 302 Found
Location: http://guide.opendns.com/?url=asdfsfdfsfdf
Content-type: text/html
Connection: close
Date: Wed, 08 Jul 2009 18:06:05 GMT
Server: OpenDNS Guide

HTTP/1.0 200 OK
Cache-Control: no-cache, must-revalidate
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Content-Type: text/html; charset=utf-8
Pragma: no-cache
Set-Cookie: t=x-1247076706; expires=Fri, 07-Aug-2009 18:06:46 GMT
Connection: close
Date: Wed, 08 Jul 2009 18:06:46 GMT
Server: OpenDNS Guide

 

This is the code (not mine) that I'm using to check the URL:

 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10); //follow up to 10 redirections - avoids loops
$data = curl_exec($ch);
curl_close($ch);
preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/",$data,$matches);
$code = end($matches[1]);
if(!$data) {
  echo "Domain could not be found";
} else {
  if($code==200) {
  	echo $data;
    echo "Page Found";
  } elseif($code==404) {
    echo "Page Not Found";
  }
}

 

What on earth is going on here? Is this something I can fix, or am I up the creek? I'm on shared hosting with private nameservers and my domain is registered with GoDaddy if that information is of any help. Thanks!

I guess these OpenDNS guys have a wildcard in the DNS system redirecting bad requests to their search page or something, so I changed my code to look for the term "opendns" and smack it down.

 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10); //follow up to 10 redirections - avoids loops
$data = curl_exec($ch);
curl_close($ch);
preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/",$data,$matches);
$code = end($matches[1]);
if(!$data) { return false; }
if(stristr($data,'opendns')){ return false; }
return $code==200 ? true : false;

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.