Get country and city with HTTPS - php

I am currently using the code below but I want an equivalent that uses HTTPS so that the browser does say that my page contains unsecured information.
<?php
$user_ip = getenv('REMOTE_ADDR');
$geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));
if(isset($geo)) {
$city = $geo["geoplugin_city"];
$region = $geo["geoplugin_regionName"];
$country = $geo["geoplugin_countryName"];
}
elseif(!isset($geo)){
$city = "NaN";
$region = "NaN";
$country = "NaN";
}
?>
Ideas?

It looks like Geoplugin.net requires a valid API key to access their API via HTTPS (therefore possibly only allowing premium users to access data via HTTPS).
The best choice for you will be contacting them about your enquiry.

Related

Payment with ePay PHP API

In the last one week and a half, I've been looking for an answer on the question: how do I get my payment API to work?
I have a test account with the Danish payment gateway provider ePay/Bambora.
I have no problem getting the JavaScript version to Work, but I'd like to do the payment by an PHP-api, to make sure I have full control on which information is hidden for people who don't need to see it, information such as my "MerchantID".
ePay/Bambora seems to be very scarce with their information on how to fulfill a payment by PHP, or else I might be blind (or can't see the forest before the trees).
This is the code I've been written:
<?php
$epay_params['merchantnumber'] = "1234567"; //fake ID
$epay_params['transactionid'] = "-1";
$epay_params['amount'] = "9995";
$epay_params['group'] = "-1";
$epay_params['paymentcollection'] = "1";
$epay_params['orderid'] = "-1";
$epay_params['pbsResponse'] = "-1";
$epay_params['epayresponse'] = "-1";
$client = new SoapClient('https://ssl.ditonlinebetalingssystem.dk/remote/payment.asmx?WSDL');
$result = $client->capture($epay_params);
if($result->captureResult == true){
echo "Result OK"; //Capture OK
}
else{
echo json_encode( $result );
}
?>
This gives the following result: {"captureResult":false,"pbsResponse":-1,"epayresponse":-1008}
According to ePay/Bambora does -1008 mean, that the transactionid isn't found.
This seems to be correct, since there is no transaction called -1. I want to create a NEW payment, so I don't have a transaction id yet.
So either I have to create a transactionid on ePay/Bamboras server BEFORE I run the payment (how?) or I should not use the method "capture", but which method should I use then?
To be clear: I am not making a webshop, but just a payment system on my new calendar webapp.
The Question is: How do I fulfill a single payment via ePay/Bambora in PHP?
Try this http_build_query() for make URL perfectly
<?php
$url = 'https://ssl.ditonlinebetalingssystem.dk/remote/payment.asmx';
$params = array('WSDL');
$url .= '?' . http_build_query($params);
$epay_params['merchantnumber'] = "1234567"; //fake ID
$epay_params['transactionid'] = "-1";
$epay_params['amount'] = "9995";
$epay_params['group'] = "-1";
$epay_params['paymentcollection'] = "1";
$epay_params['orderid'] = "-1";
$epay_params['pbsResponse'] = "-1";
$epay_params['epayresponse'] = "-1";
$client = new SoapClient($url);
$result = $client->capture($epay_params);
if($result->captureResult == true){
echo "Result OK"; //Capture OK
}
else{
echo json_encode( $result );
}
?>
Hope this work either knock me

Does Google Geocode work for anyone in 2018 is there an alternative?

Google Geocode use to work for me but does not anymore. Everything I've tried returns false. It doesn't even give a clue as to why. I've tried changing the API key, I've tried different methods to connect (I prefer using simplexml_load_file). It does work if I type the URL directly into the a browser window but not from my website or even from my localhost. Does anyone have suggestions on what to try next or an alternative to Googles Geocode service?
Here is some code that I've been using that Json / XML results.
//URL SAVE ADDRESS
date_default_timezone_set("America/Chicago");
$address = "1600 Amphitheatre Parkway, Mountain View, CA 94043";
$address = urlencode($address);
// GOOGLE URL
$url = "https://maps.googleapis.com/maps/api/geocode/xml?address=". $address ."&sensor=false&key=AIzaSyDrGe_qr4ofea8WhZFhnPGsXNQtTiQwGhw";
echo $url; //TEMP
$xml = simplexml_load_file($url) OR $ex['tblx'] = "Unable to load XML from Googleapis.";
if(empty($xml)) {
$ex['tblx'] = "Googleapis return no values.";
} elseif("" == $xml) {
$ex['tblx'] = "Geocode problem with address, revise and retry.";
} elseif("OK" != $xml->status) {
$ex['tblx'] = "Geocode: " . ("ZERO_RESULTS" == $xml->status? "Not Found": substr($xml->status,0,30));
} else{
$dvtby0 = $uca['y0'] = (double)$xml->result->geometry->location->lat; //x
$dvtbx0 = $uca['x0'] = (double)$xml->result->geometry->location->lng;
$dvtby1 = $uca['y1'] = (double)$xml->result->geometry->viewport->southwest->lat; //a
$dvtbx2 = $uca['x1'] = (double)$xml->result->geometry->viewport->southwest->lng;
$dvtbx1 = $uca['x2'] = (double)$xml->result->geometry->viewport->northeast->lng; //b
$dvtby2 = $uca['y2'] = (double)$xml->result->geometry->viewport->northeast->lat;
}//endif
if($ex) {
var_dump($ex);
}
die("did it work?");
geocoder.ca for north america
opencage or geocode.xyz for the world
pelias as standalone
there are lots of options in 2018
The problem here turned out to be the version of PHP. It's really weird and hard to troubleshoot. simplexml_load_file($url) was not returning an object. It wasn't even returning false. The only clue that it was something other that code problem. Upgrade to version 5.6 and it works ok.

json_decode return null i guess

I try to run this on my server:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
echo $ip;
$city = $details -> city;
echo $city;
?>
But, this print ip only.
Maybe a server problem or configuration?
You need to code a bit more defensively, if that site has no data for the ip address you give it, then it wont return any city property
This is a little safer
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
echo $ip . ' ';
if (isset($details->city)){
echo $details->city;
} else {
echo 'data not available';
}
Judging from what it returned for my IP Address, the details it provides are not very accurate anyway

Storing user info to database after facebook registration in joomla

I am a beginner in Joomla, I want to integrate Facebook login with my website (using Joomla 3.0), I want to know how to store the user info into my database after receiving them from facebook. Any suggestion?
Try this,
If you are using FB SDK for PHP
$path = realpath('.');
require_once($path."/facebook/fbmain.php");
$user = $facebook->getUser();
// print_r($user);
// echo "user<br/>";
// print_r($userInfo);
// echo "<br/>Info<br/>";
// print_r($fqlResult);
// foreach($fqlResult as $key=>$value){
// print_r($value);
// echo '<br>';
// }
// exit;
if ($user){
$fname = $userInfo['first_name'];
$last_name = $userInfo['last_name'];
$username = $userInfo['id'];
$dob = date("d-m-Y",strtotime($userInfo['birthday']));
foreach($fqlResult as $key=>$value);
$user_email = $value['email'];
$profile_image = $value['pic_square'];
$sex = $value['sex'];
$city = $value['hometown_location']['city'];
$state = $value['hometown_location']['state'];
$country = $value['hometown_location']['country'];
$zip = $value['hometown_location']['zip'];
//Then simply call model and write save db query.
$model = $this->getModel('Registration', 'UsersModel');
}
You want to make a FB authentication plugin and then have that pass off the data to the Joomla user plugin if possible. If you want to use a different user table you would need to make your own user plugin as well. Joomla auth first authenticates (authentication plugin), then authorsises, then logs in (user plugin)

Wialon remote API login

My code:
<?php
if(isset($_GET['login']) && isset($_GET['login']) && isset($_GET['password'])){
$_login_url = "http://testing.wialon.com/wialon/ajax.html?svc=core/login&params={user:%s,password:%s}";
$login = $_GET['login'];
$password = $_GET['password'];
$handle = fopen(sprintf($_login_url, $login, $password), "r");
$line = fgets($handle);
fclose($handle);
$responce = explode(",",$line);
if(count($responce) < 2) {
echo "Invalid user or password";
} else {
$sessid = explode(":",$responce[1]);
$lastid = str_replace("\"","",$sessid[1]);
echo "http://testing.wialon.com/index.html?sid=".$lastid."";
}
}
?>
when I access this script with the server hosting the script everything works perfectly, The sessions are generated with my IP address.
But when I access it with another computer any user trying to login the script generates session using the servers IP address. can I send the request with the users IP address?
No, you cannot send the request with the users IP address.
However, you might be able to indicate that the request is being performed on behalf of another IP by using the HTTP_X_FORWARDED_FOR request header or similar, but without looking at their documentations (which doesn't seem to be publicly available) I can't be sure of it. You'll need to ask 'em.
This is an old thread but, let me put in my two cents. There are two new wialon athentication methods Token login and by passing the athorization hash . the second method is best suited for maintaining session across servers.
http://sdk.wialon.com/wiki/en/kit/remoteapi/apiref/core/create_auth_hash
http://sdk.wialon.com/wiki/en/kit/remoteapi/apiref/token/token
//get the Token from here http://hosting.wialon.com/login.html?client_id=wialon&access_type=-1&activation_time=0&duration=0&flags=1
// You should have your existing username from wialon with SDK access
$params = "{'token':'$token','operateAs','$username'}";
$baseurl = "http://hst-api.wialon.com/wialon/ajax.html";
$url = "$baseurl?params=".urlencode($params)."&svc=token/login";
$o = json_decode(file_get_contents($url),true);
$sid = $o['eid'];

Categories