domain validation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Vince
Forum Newbie
Posts: 4
Joined: Wed Mar 24, 2004 5:12 pm

domain validation

Post by Vince »

Hi Everyone,

I am creating an order form for a hosting company.

The actual form for the domain registration page has 1 text box, 1 drop down list and 2 radio buttons.

Visitors are supposed to type there domain in the text box just like this:
"mydomain"
Then they are supposed to select their extension from the drop down list. Ex... .com, .net ect...

Then they are supposed to select 1 of 2 radio buttons. "Either the domain is registered or it isn't."

If they select that it's NOT registered, then my script checks to see if the domain is available. If they select that it's already registered, they move on to the next section of the order form.

Here's the problem. Some people can not follow simple directions, so in the box they type mydomain.com.

That is fine, my script removes any http://, https://, ftp://, http://www., and removes any valid extension they add to it. (ie.. .com, .net, .info ect..).

My script is not yet smart enough to remove subdomains though. If someone were to type in the box:
http://forums.mydomain.com/ my script would see: forums.mydomain.com

My script would come back and say that the domain is available, and I can not register sub-domains.

Here is my current code which removes all the bad stuff (Except Sub-Domains)

$domain = str_replace("www.", "", $domain);
$domain = str_replace("http://", "", $domain);
$domain = str_replace(".com", "", $domain);
$domain = str_replace(".net", "", $domain);
$domain = str_replace(".org", "", $domain);
$domain = str_replace(".info", "", $domain);
$domain = str_replace(".biz", "", $domain);
$domain = str_replace(".edu", "", $domain);
$domain = str_replace(".cc", "", $domain);
$domain = str_replace(".ca", "", $domain);
$domain = str_replace(".org.uk", "", $domain);
$domain = str_replace(".co.uk", "", $domain);
$domain = str_replace(".ws.uk", "", $domain);
$domain = str_replace(".us.uk", "", $domain);
$domain = str_replace("/", "", $domain);

Now after all this is done, I need something to check the domain and see if it is in a sub-domain format. If it is a subdomain, then the script needs to remove only the subdomain and the period. subdomain.mydomain.com

Any sample code would be great.

Thanks,

Vince
fangorn
Forum Commoner
Posts: 41
Joined: Fri May 21, 2004 9:04 am

Post by fangorn »

After your str_replace code, you could use the explode function and count the elements. If I understand you correctly, any sub-domains wouldn't be stripped off by your str_replace code and therefore the explode function would return more than 1 element. Or use strtok to count the dots. Or use substr_count.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Hmmmm....perhas you should use a ready made PHP function for grabbing the parts of a URL!?

parse_url()

Mark
Vince
Forum Newbie
Posts: 4
Joined: Wed Mar 24, 2004 5:12 pm

Post by Vince »

substr_count works perfectly.

Here is the code:

Code: Select all

<?php
   	$variables = 0;
   	$domain = str_replace("www.", "", $domain);
	$domain = str_replace("http://", "", $domain);
	$domain = str_replace(".com", "", $domain);
	$domain = str_replace(".net", "", $domain);
	$domain = str_replace(".org", "", $domain);
	$domain = str_replace(".info", "", $domain);
	$domain = str_replace(".biz", "", $domain);
	$domain = str_replace(".edu", "", $domain);
	$domain = str_replace(".cc", "", $domain);
	$domain = str_replace(".ca", "", $domain);
	$domain = str_replace(".org.uk", "", $domain);
	$domain = str_replace(".co.uk", "", $domain);
	$domain = str_replace(".ws.uk", "", $domain);
	$domain = str_replace(".us.uk", "", $domain);
	$domain = str_replace("/", "", $domain);
	$variables = substr_count($domain, ".");
	
	if ($variables > 0)
	{
		$message = "<font color="red"><B>" . $domain . $ext . " is a sub domain.</B></font>";
		require('includes/templates/getdomain.tpl');
		require('includes/footer.php');
		exit;
	}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

unless it's an IP... ;)
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

but an IP isn't a domain
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

true.. but that probably should be in the filtering... :roll:
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

yea
Post Reply