faisal Posted October 29, 2015 Share Posted October 29, 2015 Hi all I have a simple Custom HTML Panel <?php if (!defined("WHMCS")) die("This file cannot be accessed directly"); use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) { $customMessage = $secondarySidebar->addChild('Custom Title'); $customMessage->moveToBack(); $customMessageHtml = <<<EOT <div>My custom HTML message.</div> EOT; $secondSidebar = $secondarySidebar->getLastChild(); $secondSidebar->setBodyHtml($customMessageHtml); }); Can I display the panel only for visitor from specific country by country iso code? for example "fr" or "de"? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 29, 2015 Share Posted October 29, 2015 Can I display the panel only for visitor from specific country by country iso code? for example "fr" or "de"? if the visitor was a client and logged in, then yes you could easily do it in the hook; if this is a sidebar for everyone, then you'd have to use a geo-ip service to convert the IP address to a country. 0 Quote Link to comment Share on other sites More sharing options...
faisal Posted November 1, 2015 Author Share Posted November 1, 2015 Yes, that is all I can find tell now, thanks. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 1, 2015 Share Posted November 1, 2015 Yes, that is all I can find tell now, thanks. which one are you trying to do - for logged in clients or everyone ? 0 Quote Link to comment Share on other sites More sharing options...
faisal Posted November 2, 2015 Author Share Posted November 2, 2015 which one are you trying to do - for logged in clients or everyone ? everyone. But I want to show/hide the whole panel, not just the html content. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 2, 2015 Share Posted November 2, 2015 try the following - change the 'FR' value to the ISO code value for the country that you want to allow to see the panel... e.g it currently shows the panel to users in France, any other country won't see it. <?php if (!defined("WHMCS")) die("This file cannot be accessed directly"); use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) { $current_country = ''; $ret = file_get_contents("http://api.hostip.info/get_json.php?ip=".$_SERVER['REMOTE_ADDR']); $parsed_json = @json_decode($ret,true); if(isset($parsed_json['country_code'])) { $current_country = $parsed_json['country_code']; } if ($current_country!="FR"){ return; } $customMessage = $secondarySidebar->addChild('Custom Title'); $customMessage->moveToBack(); $customMessageHtml = <<<EOT <div>My custom HTML message.</div> EOT; $secondSidebar = $secondarySidebar->getLastChild(); $secondSidebar->setBodyHtml($customMessageHtml); }); the country code part is taken from the Geo-IP hook @ http://www.blog.modulesgarden.com/automatic-currency-and-language-setup-for-whmcs/ - if it is too slow for your needs (as it currently queries another website to determine the country), upload the Maxmind database to your server and use the code (parts 4, 5 & 6) for maxmind in the blog. 1 Quote Link to comment Share on other sites More sharing options...
faisal Posted November 3, 2015 Author Share Posted November 3, 2015 First of all: Thank you for your time and help. Second: The hostip.info didn't work for me at all and with simple test I see that not all countries are listed (at least my country or my IP, I am really not sure): <?php if (!defined("WHMCS")) die("This file cannot be accessed directly"); use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) { $current_country = ''; $ret = file_get_contents("http://api.hostip.info/get_json.php?ip=".$_SERVER['REMOTE_ADDR']); $parsed_json = @json_decode($ret,true); if(isset($parsed_json['country_code'])) { $current_country = $parsed_json['country_code']; } if ($current_country != "FR"){ //return; } $customMessage = $secondarySidebar->addChild('Custom Title'); $customMessage->moveToBack(); $customMessageHtml = <<<EOT <div>My custom HTML message.</div> <div>Country Code: $current_country</div> EOT; $secondSidebar = $secondarySidebar->getLastChild(); $secondSidebar->setBodyHtml($customMessageHtml); }); It will show: My custom HTML message. Country Code: XX So I did it with maxmind and it's working <?php if (!defined("WHMCS")) die("This file cannot be accessed directly"); use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) { $current_country = ''; /* $ret = file_get_contents("http://api.hostip.info/get_json.php?ip=".$_SERVER['REMOTE_ADDR']); $parsed_json = @json_decode($ret,true); if(isset($parsed_json['country_code'])) { $current_country = $parsed_json['country_code']; } */ include "geoip.inc"; $gi = geoip_open(dirname(__FILE__).DIRECTORY_SEPARATOR."GeoIP.dat", GEOIP_STANDARD); $current_country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']); geoip_close($gi); if ($current_country != "FR"){ //return; } $customMessage = $secondarySidebar->addChild('Custom Title'); $customMessage->moveToBack(); $customMessageHtml = <<<EOT <div>My custom HTML message.</div> <div>Country Code: $current_country</div> EOT; $secondSidebar = $secondarySidebar->getLastChild(); $secondSidebar->setBodyHtml($customMessageHtml); }); Now it is showing the Country Code: My custom HTML message. Country Code: (It's Showing the country code) * I just comment/disable the return in the if condition for testing only so I can see the Country Code in all cases 0 Quote Link to comment Share on other sites More sharing options...
faisal Posted November 3, 2015 Author Share Posted November 3, 2015 If I use my browser go to http://api.hostip.info/get_json.php?ip=My-IP-address All I get is: {"country_name":"(Unknown Country?)","country_code":"XX","city":"(Unknown City?)","ip":"My-IP-address"} Maybe something wrong from my end because even here in the forum can't edit my posts! and if i wrote something and hit the review button I always get a human verification page, and sometimes when I do it my post deleted and had to write again. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 3, 2015 Share Posted November 3, 2015 First of all: Thank you for your time and help. my pleasure. The hostip.info didn't work for me at all and with simple test I see that not all countries are listed (at least my country or my IP, I am really not sure): the maxmind database option should be more accurate anyway, so I wouldn't worry about hostip if you don't need to use it - it worked for me in the UK. Maybe something wrong from my end because even here in the forum can't edit my posts! and if i wrote something and hit the review button I always get a human verification page, and sometimes when I do it my post deleted and had to write again. what happens when you go to http://www.hostip.info/use.html - does it show your country flag? if not, it probably just means your IP address/block is not in their database... 0 Quote Link to comment Share on other sites More sharing options...
clapcreative Posted November 3, 2015 Share Posted November 3, 2015 this is for everyone or specific person ?? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 3, 2015 Share Posted November 3, 2015 it's for everyone in the specified country or countries. 0 Quote Link to comment Share on other sites More sharing options...
faisal Posted November 3, 2015 Author Share Posted November 3, 2015 what happens when you go to http://www.hostip.info/use.html - does it show your country flag? if not, it probably just means your IP address/block is not in their database... No flag. just a question mark image with a funny message that says: ... actually we haven't a clue. lol I will use maxmind Thanks - - - Updated - - - They let my add my Ip Is this wrong? Make a correction (link) that go to http://www.hostip.info/correct.html?spip=your-IP 0 Quote Link to comment Share on other sites More sharing options...
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.