Php code for geoplugin is not working with drupal 7 -
I have php code for geoplugin, it's working fine, if I run it as a normal php file But when I add it to the Drupal site .tpl.php file, it's not working at all I've tried in several ways that I found! And on the other but not all but come at all. And I am using var_dump (..) which contains the Geopaglen array but the value is only null, my code is the latest I am using:
function visitor_country () { $ Client = @ $ _ SERVER ['HTTP_CLIENT_IP']; $ Forward = @ $ _ Server ['HTTP_X_FORWARDED_FOR']; $ Remote = $ _SERVER ['REMOTE_ADDR']; $ Result = "unknown"; If (filter_var ($ client, FILTER_VALIDATE_IP)) {$ ip = $ client; } Otherwise (filter_var ($ Forwarded, FILTER_VALIDATE_IP)) {$ ip = $ Forwarded; } And {$ ip = $ remote; } $ Ip_data = @ json_decode (file_get_contents ("http://www.geoplugin.net/json.gp?ip=". $ Ip)); If ($ ip_data & ip_data-> geoplugin_countryName! = Null) {$ result = $ ip_data- & gt; Geoplugin_countryName; } Return result; } Please tell me what is wrong with me.
The general idea is that you should not write any business logic in tpl.php files at all . PHP code will work, but it's not right. You must have a separate module for that argument. Have you tried finding the appropriate module on drupal.org? I have written the integration for geoplugin.com and Drupal on PHP, you can see it here:. When you read it, it can be included in the stable release of the module, you can see it on the project page here
Comments
Post a Comment