PDA

View Full Version : If domain exists



Ultragames
05-06-2005, 05:55 PM
I need a function in which I can pass it a domain name, (codingforums.com) and it will check to see if this domain exists. This could just be done by checking to see if there is any results on the page. I see no way to do it in PHP, and i really need to be able to do this in real time.

Even if you think it can't be done, please let me know.

Thanks for any ideas.

Brandoe85
05-06-2005, 11:32 PM
You could try to open the URL in php, probably...



<?php
error_reporting(E_ERROR | E_PARSE);
$domain = fopen('http://www.codingforums.com', 'r');

if(!$domain)
{
echo 'Nope';
exit;
}
else
{
echo 'Yep';
}

?>

brandonH
05-08-2005, 05:37 PM
this one is a bit longer but it works as well plus it can detect files on your computer as long as they are within the same folder as this file or sub folders. (to detect files on your computer though you must type in the whole path name starting with this files folder as the root folder)

when this checks the domain it grabs the http status. if the status is 200 the site exsists. if it is 404 it doesnt exsist. now there are other possible returns that can come back but they are mostly things like unauthorized access and stuff, so its just the same as if its not there to me. (if I cant view it, what good is it?)


<script type='text/javascript'>
function CheckDomain(Address){
alert(Address);
var s=getHTTPStatus(Address);alert(s);
if (s=='200' || s=='0'){ //found
alert('The domain:\"'+Address+'\" does exsist.');
} else{alert('The domain:\"'+Address+'\" does not exsist.');}
return true;

}

function getHTTPStatus(Domain){
// this function is the one that checks for the domains status
var oxmlhttp = null;
try{ oxmlhttp = new XMLHttpRequest();}
catch(e){
try{ oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){ return -1;}
}
if(!oxmlhttp) return -1;
try{
oxmlhttp.open("GET",Domain,false);
oxmlhttp.send(null);
}
catch(e){ return -1;}
return oxmlhttp.status;
}
</script>