M
M
Michael2010-11-08 22:36:34
PHP
Michael, 2010-11-08 22:36:34

PHP. What is the best way to check if a site exists or not

there is a site address, what is the best way to check its existence? CURL
get_headers fsockopen fopen

Answer the question

In order to leave comments, you need to log in

8 answer(s)
A
Andrey Bazykin, 2010-11-09
@FAT

I made such an implementation in PHP, here is the working code:
<?
$website = " www.site.ru "
// Open a socket connection and bind it to a variable
$sock = fsockopen($website, 80, $errno, $errstr);
//If the connection is not established, then there will be an error
if (!$sock)
{
echo("$errno($errstr)");
return;
}
//Otherwise, check if the resource is available and write the result
else
{
fputs ($sock, "GET / HTTP/1.0\r\nHost: www.example.com \r\n\r\n");
$status = substr(str_replace(":",": ", fgets($sock,128)), 9);
if(substr($status,0,6)!="200 OK")
echo "Site not available!"
}
//Close the connection
fclose ($sock);
?>

V
videns, 2010-11-09
@videns

Use the gethostbyname function:
www.php.net/manual/en/function.gethostbyname.php
If it returns an ip, then the site is registered and delegated

M
MyraJKee, 2010-11-08
@MyraJKee

If you just check, then curl. Written in C. I.e. lower-level language... Therefore, it should work faster... In general, if you are not engaged in mass spam or invent spiders or something like that, write as it suits you.

V
Vlad Zhivotnev, 2010-11-08
@inkvizitor68sl

No way.
If the domain points to any IP and at least some site is spinning on this IP, then the default site for the IP will open on the domain.

S
Shizz, 2010-11-08
@Shizz

Well, a more or less acceptable option is to read the HTTP status code. This will only allow you to find out that a web server is running on this domain. But in fact, there may be a REST backend for AJAX muzzle, for example. No more or less quick check will give one hundred percent probability.

S
slang, 2010-11-09
@slang

It's not entirely clear what you want to do. If you find out if the domain exists (is delegated), contact the Whois service with CURL, of which there are many on the Internet, and parse the answer. If a web server is spinning at the address specified by the domain name, use CURL to pull this name and parse the response. If you fall off on a timeout - no, if they answer - there is something. And if the site is alive at the moment, then also parse the response / error code.

K
klepton, 2010-11-09
@klepton

nsllokup

K
klepton, 2010-11-09
@klepton

sorry, nslookup

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question