flangefrog Posted September 5, 2014 Report Posted September 5, 2014 Why does the getTLD() function in the domain modules compare against the module's TLD list? If the TLDs are not in the right order e.g. Configure::set("Webdrive.tlds", array( ".nz", ".co.nz", )); then the domain example.co.nz would return .nz instead of .co.nz. It also doesn't limit the returned value to those in the TLD list. Why not just use the last line? private function getTld($domain) { $tlds = Configure::get("Enom.tlds"); $domain = strtolower($domain); foreach ($tlds as $tld) { if (substr($domain, -strlen($tld)) == $tld) return $tld; } return strstr($domain, "."); } Quote
Blesta Addons Posted September 6, 2014 Report Posted September 6, 2014 i think you have a error in your get $tlds = Configure::get("Enom.tlds"); it should per your sample $tlds = Configure::get("Webdrive.tlds"); wich system that .nz use ? is(CoCCA) ? you are writing a module for it ? Quote
flangefrog Posted September 6, 2014 Author Report Posted September 6, 2014 That was just because I copied the code from two different modules. I'm thinking of just using private function getTld($domain) { return strstr($domain, "."); } for my module though. I'm not familier with CoCCA but I just looked it up. It seems they make software for registries right? Although they are a New Zealand company they don't seem to mention that it is used for the .nz registry. I'm not a registrar so I am using Web Drive for registering NZ domains. I started building a module for Web Drive several months ago but put it aside while waiting for a reply to one of my support tickets regarding the API (still no reply). I have been using it in production but today I'm working on finishing it so I can actually use it to register/renew/transfer domains. Quote
Blesta Addons Posted September 9, 2014 Report Posted September 9, 2014 try this code private function getTld($domain, $top = false) { $tlds = Configure::get("Webdrive.tlds"); $domain = strtolower($domain); if (!$top) { foreach ($tlds as $tld) { if (substr($domain, -strlen($tld)) == $tld) return $tld; } } return strrchr($domain, "."); } if is not the result you need , change $top = false to $top = true . Quote
flangefrog Posted September 9, 2014 Author Report Posted September 9, 2014 Thanks for that, I actually ended up removing the getTld() function as my registrar doesn't require me to split the TLD off. I still don't understand why the method would even be getting the TLDs from the configuration, there seems to be no point in it? Quote
Blesta Addons Posted September 9, 2014 Report Posted September 9, 2014 Thanks for that, I actually ended up removing the getTld() function as my registrar doesn't require me to split the TLD off. I still don't understand why the method would even be getting the TLDs from the configuration, there seems to be no point in it? it help for adding some extra info in some ccTld . for exemple .US or .CA or .ES .... Quote
flangefrog Posted September 9, 2014 Author Report Posted September 9, 2014 it help for adding some extra info in some ccTld . for exemple .US or .CA or .ES .... Yes, I understand that but what I don't understand is the real world difference between the small function I wrote and the original one. Consider the following code: function getTldA($domain) { $domain = strtolower($domain); return strstr($domain, "."); } function getTldB($domain) { $tlds = array( ".co.nz", ".kiwi.nz", ".nz", ); $domain = strtolower($domain); foreach ($tlds as $tld) { if (substr($domain, -strlen($tld)) == $tld) return $tld; } return strstr($domain, "."); } function getHtml($function, $domain) { return $domain . ": <strong>" . $function($domain) . "</strong><br>"; } echo "<h1>getTldA()</h1>"; echo getHtml("getTldA", "domain.nz"); echo getHtml("getTldA", "domain.co.nz"); echo getHtml("getTldA", "domain.net.nz"); echo getHtml("getTldA", "domain.com"); echo getHtml("getTldA", "test.domain.nz"); echo getHtml("getTldA", "test.domain.co.nz"); echo getHtml("getTldA", "test.domain.com"); echo getHtml("getTldA", "test.domain.net.nz"); echo "<h1>getTldB()</h1>"; echo getHtml("getTldB", "domain.nz"); echo getHtml("getTldB", "domain.co.nz"); echo getHtml("getTldB", "domain.net.nz"); echo getHtml("getTldB", "domain.com"); echo getHtml("getTldB", "test.domain.nz"); echo getHtml("getTldB", "test.domain.co.nz"); echo getHtml("getTldB", "test.domain.com"); echo getHtml("getTldB", "test.domain.net.nz"); The output given by this code is:getTldA() domain.nz: .nz domain.co.nz: .co.nz domain.net.nz: .net.nz domain.com: .com test.domain.nz: .domain.nz test.domain.co.nz: .domain.co.nz test.domain.com: .domain.com test.domain.net.nz: .domain.net.nz getTldB() domain.nz: .nz domain.co.nz: .co.nz domain.net.nz: .nz domain.com: .com test.domain.nz: .nz test.domain.co.nz: .co.nz test.domain.com: .domain.com test.domain.net.nz: .nz As you can see the main difference is with subdomains or domains not specified in the configuration. getTldA() is more consistent and gets domains like domain.net.nz right. I would argue that the subdomains are also correct as all CentralNic domains are subdomains for example or you may even want to sell subdomains of a domain you own like *.shop.nz. If there is any validation to be done (e.g. not allowing subdomains) it should be in the user input phase like when ordering or adding through the admin panel. Quote
Blesta Addons Posted September 9, 2014 Report Posted September 9, 2014 there are difference .first you need to adjust your $tlds array . $tlds = array( ".co.nz", ".kiwi.nz", ".net.nz", ".nz", ); getTldA() domain.nz: .nzdomain.co.nz: .co.nzdomain.net.nz: .net.nzdomain.com: .comtest.domain.nz: .domain.nz --- wrong resuttest.domain.co.nz: .domain.co.nz --- wrong resuttest.domain.com: .domain.com --- .com are not in array .test.domain.net.nz: .domain.net.nz --- wrong resut getTldB()domain.nz: .nzdomain.co.nz: .co.nzdomain.net.nz: .nzdomain.com: .comtest.domain.nz: .nz --- correct extractiontest.domain.co.nz: .co.nz --- correct extractiontest.domain.com: .domain.com --- .com are not in array .test.domain.net.nz: .nz --- correct extraction Quote
flangefrog Posted September 9, 2014 Author Report Posted September 9, 2014 I think what I was trying to say is that the getTld() function should never see test.domain.co.nz (unless you actually want to sell subdomains of domain.co.nz) and should be validated by a different function first. Quote
Cody Posted September 9, 2014 Report Posted September 9, 2014 Different registrars require different "extended fields" based on TLD. .co.uk is not the same as .uk with respect to TLD submitted to registrars that require separting TLD from SLD (despite the fact that, by definition, TLD means top level, e.g. .uk). This is probably due to country TLDs not being resold through various countries directly until recently. Quote
Blesta Addons Posted September 9, 2014 Report Posted September 9, 2014 I think what I was trying to say is that the getTld() function should never see test.domain.co.nz (unless you actually want to sell subdomains of domain.co.nz) and should be validated by a different function first. you can use a custom regex for $domain to see if exist a "." in it after substract the TLD extention . so if exist return a error (false) or procced (true) . Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.