Elxis CMS Forum

Support => General => Topic started by: xmanhattan on July 23, 2019, 13:03:12

Title: elxis 5.5 contact plugin geobytes
Post by: xmanhattan on July 23, 2019, 13:03:12
Hello all,

I am trying to implement geobytes into the contact plugin file contact.plugin.php by adding the following code into line 598.

I am using the IP number variable provided in the contact plugin to obtain the json info from geobytes but it does not seem to work.

Code: [Select]
//*********************************************************************
// begin geobytes latest method
//*********************************************************************
$client_ip = $ipaddr; // copied from Elxis variable above

$tags=json_decode(file_get_contents('http://gd.geobytes.com/GetCityDetails?fqcn='. $client_ip), true);

$geobyteslatitude  = $tags['geobyteslatitude']; // get coordinates if you want to use
$geobyteslongitude = $tags['geobyteslongitude']; // visual Google map link as shown below

// values of country, city, etc...
$body .= "country   ".$tags['geobytescountry']."\n";
$body .= "region    ".$tags['geobytesregion']."\n";
$body .= "city      ".$tags['geobytescity']."\n";
$body .= "latitude  ".$tags['geobyteslatitude']."\n";
$body .= "longitude ".$tags['geobyteslongitude']."\n";
$body .= 'http://maps.google.com/?q='.$geobyteslatitude.','.$geobyteslongitude.''."\n";
$body .= "\n\n";
//*********************************************************************
// end geobytes
//*********************************************************************

Although I have the same code working on Elxis 3.x, this does not.

I assume that the line
Code: [Select]
$ipaddr = $elxis->obj('ip')->clientIP(false, false); produces a regular ip address since the next line simply changes it into text for output to the email.

Could it be that the tags line is not working within the contact code?
I checked that the link is working using http://gd.geobytes.com/GetCityDetails?fqcn=193.92.200.103 (http://gd.geobytes.com/GetCityDetails?fqcn=193.92.200.103)
It returns the json properly.

Title: Re: elxis 5.5 contact plugin geobytes
Post by: datahell on July 23, 2019, 15:03:58
Function file_get_contents will not work with URLs unless the PHP directive allow_url_fopen is on which is considered insecure and most probably will be off in your server (check it).
The proper way to request remote resources in PHP is with CURL. An alternative way is to use javascript.
Title: Re: elxis 5.5 contact plugin geobytes
Post by: xmanhattan on August 01, 2019, 17:35:27
Hello datahell,

Sorry for the delay in answering.
I have corrected the files for inclusion of geolocation using curl and tested it successfully.

This is only for the latest version of Elxis 5.0 and assumes that you use Php 5.6 or later.
I am attaching a zip file with the modifications for contact and anyform, if anyone is interested.
After unzipping in a temporary folder, you can see which files have been modified and ONLY replace those if you wish.
As always, MAKE A BACKUP OF YOUR ORIGINALS before replacing them!

Have a nice summer everyone!