hello, i want anything to check to see if this domain exists for example. www.google.com PHP: this is good url but this one www.hjifodszhgfiodshgfo.com PHP: ops there are none site like that so is there any way to validate this with php and echo a message back thanks in advance
function is_valid_dns($dns) { if(gethostbyname($dns) == $dns) return false; return true; } PHP: haven´t tested it but it should work... More information on Gethostbyname
no it didn't worked, this is not what im looking for. i just want something to tell whether if the url is right and have content or wrong the if condition is not working, if you test book.com it's going to say false and actually book.com exists thanks for help
if(file('http://www.book.com')): echo 'EXISTS'; else: echo 'DOESN\'T EXIST'; endif; PHP: that could be a control..
then there´s something wrong with your server since that works on mine using <?php function is_valid_dns($dns) { if(gethostbyname($dns) == $dns) return false; return true; } if(is_valid_dns("book.com")) { print "true"; } else { print "false"; } ?> PHP: you can see it at => http://www.qsdchublist.com/gethost.php
it works but the problem that when the domain is false it get me a php error like that Warning: file() [function.file]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\mysite\index.php on line 23 Warning: file(http://www.bhfdshfdshfdsagook.com) [function.file]: failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\mysite\index.php on line 23 DOESN'T EXIST HTML: so do you got any idea to only make it show DOESN'T EXIST
see the output of this php function, and you can use the data to see if website exists or not: echo '<pre>'; print_r(get_headers('http://www.book.com')); exit; Code (markup): The reason other functions are returning an error is because the domain book.com is a 301 redirect to another url. You can see this info using this function and your script can decide if it actually exists or not. Thanks
This is one of the most resource-consuming alternatives that I have ever seen to do what the OP asks for... My suggestion: http://php.net/manual/en/function.curl-getinfo.php (I think there's a way to use it without executing curl_exec before)
i don't have that big of knowlade with php, but i think the code above works pretty well, and i tested it a lot of times and it gives me exactly what i need. so if you do have a way to use your code and gives me the same result, tell me how can i use it, cuz on the page you gave me on php.net none people talking about it.
I can't afford to do your work. I just pointed you in the right direction - "teach them to fish instead of giving them the fish"
<?php $headers = get_headers("http://www.google.com", 1); if ($headers[0] == "HTTP/1.1 200 OK" || $headers[0] == "HTTP/1.0 200 OK"){ echo "Exists"; } else { echo "Doesn't exist"; } ?> PHP:
this works but it's give me a php error if the url is wrong one try to type www.ijngshgdslnhifds.com HTML: and you have to make this $headers[0] like that $headers[1]