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
domain validation
Moderator: General Moderators
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.
Hmmmm....perhas you should use a ready made PHP function for grabbing the parts of a URL!?
parse_url()
Mark
parse_url()
Mark
substr_count works perfectly.
Here is the code:
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;
}
?>-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA