Thu, December 2, 2021
 
https://devcodepro.comdevcodepro
X
InterServer Web Hosting and VPS
Home · Latest · Trends
4

Validate domain name with PHP

Validate domain name with PHP gethostbyname
<?php
// index.php
if(isset($_POST['submit'])) {
if(get_magic_quotes_gpc()) {
$domainname = htmlspecialchars(stripslashes($_POST['domainname']));
} else {
$domainname = htmlspecialchars($_POST['domainname']);
}
if(!filter_var(gethostbyname($domainname),FILTER_VALIDATE_IP)) {
echo "false";
} else {
echo "true";
}
} else {
?>
<form method="post" action="index.php">
Domain Name<br />
<input class="input" placeholder="example.com" name="domainname" type="text" /><br />
<br />
<input type="submit" value="Submit" name="submit" />
</form>
<?php } ?>
rated 4 times (4) (0)
comments: 0 / hits: 2972  / 5 years ago, sat, sep 10, 16, 03:13:33
More From » PHP
 

Comments

There are no comments for this Snippet yet
Only authorized users can post. Please sign in first, or register a free account
Login with Google
 
Share
Posted
Michael
Member since Sep 10, 2016
Total Code Snippets: 5
Total Comments: 0
Location: n/a
Michael snippets
5 years ago, sat, sep 10, 16, 3:07:57
comments: 2 / hits: 6051
PHP
5 years ago, sat, sep 10, 16, 3:16:20
comments: 0 / hits: 3057
PHP
5 years ago, sat, sep 10, 16, 3:19:13
comments: 1 / hits: 7058
PHP
5 years ago, tue, feb 21, 17, 2:06:26
comments: 0 / hits: 2422
PHP