php xml Google Geocoding Error - php

if i understand the google error OVER_QUERY_LIMIT right, than it comes because of too many ip-requests.
BUT if I go to the browser and load the following link:
http://maps.googleapis.com/maps/api/geocode/xml?address=Paris&sensor=true
I can see the xml!
So why is that?
Do I have a problem in my code?
Here it is:
$the_map = htmlspecialchars($_POST['map'], ENT_QUOTES);
error_reporting(0);
$map_query = file_get_contents('http://maps.google.com/maps/api/geocode/xml?address='.rawurlencode($the_map).'&sensor=false');
error_reporting(1);
if ($map_query){
$geo_code = simplexml_load_string(utf8_encode($map_query));
if ($geo_code){
$map_lat = $geo_code->xpath("/GeocodeResponse/result/geometry/location/lat");
$map_lng = $geo_code->xpath("/GeocodeResponse/result/geometry/location/lng");
$map_lat = $map_lat[0][0];
$map_lng = $map_lng[0][0];
}
}

Use curl instead of file_get_contents:
$address = "India+Panchkula";
$url = "http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false&region=India";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);
echo $lat = $response_a->results[0]->geometry->location->lat;
echo "<br />";
echo $long = $response_a->results[0]->geometry->location->lng;
Or See the below URL
Warning while using file_get_contents for google api

Related

PHP rest service

I'm new to PHP and i'm trying to send this of to a webservice.
<?php
$myID = "8125987";
$myVarible = "This is a test";
$service_url = "https://...?password=123&user=123&storeid=1000&mobile=$myID&message=$myVarible";
$curl = curl_init($service_url);
$result = curl_exec($curl);
curl_close($curl);
echo $result;
?>
It is not working, what is wrong?
Thanks for any help.
KHJ
1) Check if your curl function exists first
echo function_exists('curl_version') ? 1:0; // 1 = enabled , 0 =
disabled.
2) Try to access example.com instead of your target url
$url = "http://www.example.com";
3) Print out the curl info and err message before you asked a question
There're lots of CURL examples on the internet, however, I still did one for your reference.
https://www.stockeasymoney.com/ns/sit/curlRaw.php
<?php
echo function_exists('curl_version') ? 1:0; // 1 = enabled , 0 = disabled.
echo "<pre>";
$url = "http://www.example.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$result = curl_exec($ch);
print_r( curl_getinfo($ch) );
curl_close($ch);
var_dump($result);
echo "</pre>";
?>

how to integrate atom payment gateway in PHP

I am using ATOM payment gateway and YII framework. I am using following code & i am not getting response here $returnData = curl_exec($ch); its returning empty.
Please tell how can i come over it. is ther any tutorials for this integration.
$url = ‘http://203.114.240.77/paynetz/epi/fts';// test bed URL
$port = 80;
$atom_prod_id = “NSE”;
// code to generate token
$param = "&login=".$userid."&pass=".$password."&ttype=NBFundTransfer&prodid=".$atom_prod_id."&amt=".$amount."&txncurr=INR&txnscamt=0&clientcode=".$clientcode."&txnid=".$invoiceid."&date=".$today."&custacc=12345";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_PORT , $port);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
$returnData = curl_exec($ch);
// Check if any error occured
if(curl_errno($ch))
{
echo ‘Curl error: ‘ . curl_error($ch);
}
curl_close($ch);
$xmlObj = new SimpleXMLElement($returnData);
$final_url = $xmlObj->MERCHANT->RESPONSE->url;
// eof code to generate token
// code to generate form action
$param = “”;
$param .= “&ttype=NBFundTransfer”;
$param .= “&tempTxnId=”.$xmlObj->MERCHANT->RESPONSE->param[1];
$param .= “&token=”.$xmlObj->MERCHANT->RESPONSE->param[2];
$param .= “&txnStage=1″;
$url = $url.”?”.$param;
// eof code to generate form action
Please check for the http response code. Are you expecting any data to be returned? You're posting data, maybe the response-body should be empty?
Please add the code below to check for the http status code.
$info = curl_getinfo($ch);
echo $info["http_code"];

Process request of cURL

I made a cURL request code and i'd like to process the data it sends.
cURL code:
$url = "http://rbvconsultancy.com/api/post.php";
$xml_builder = '<?xml version = "1.0" ?>
<request>
<no>1</no><dat>hello</dat>
</request>';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_builder);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 28);
$ch_result = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$rest = $ch_result;
echo $rest;
process cURL:
echo "hello".$_GET['para1'];
Based on the code above, i'd like my process cURL code to get the value of $xml_builder. Any ideas on how to do it? It seems that $_GET['para1'] doesnt do the job.
I guess you want this :
you can copy this to your response PHP file
echo file_get_contents("php://input");
Maybe this will help you

cURL with PHP - HTTP cURL to HTTPS

I have the following bit of PHP, it works locally (via apache and localhost) but not on my hosting - $response is always empty:
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$api_key = 'my_api_key';
$randomString = generateRandomString(10);
$endLabel = sha1(md5($randomString));
$user_id = $endLabel;
$amount_doge = '5';
$url = "https://dogeapi.com/wow/?api_key=".$api_key."&a=get_new_address&address_label=".$user_id;
$response = get_data($url);
I wondered if this could be because I'm hosted on HTTP (no SSL option) and I'm calling a HTTPS domain? If so, is there a way around this? I've tried curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); but it doesn't seem to do anything :(
try to use echo curl_error($ch) after $data = curl_exec($ch); to see what curl says
it wil lreport you what happened

getting Latitude And Longitude From Pin Code Using PHP

In my site i want to get the latitude and longitude of given pin code or postal code.
If i give 680721 as pin code or postal code then i want to get its corresponding latitude and longitude using php code.
How can i do this?
If this is possible in PHP?
I have php code to get latitude and longitude of given name of place.
$Url='http://maps.googleapis.com/maps/api/geocode/json?address='.$exp_pjctloc[$i].'&sensor=false';
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
$search_data = json_decode($output);
$lat = $search_data->results[0]->geometry->location->lat;
$lng = $search_data->results[0]->geometry->location->lng;
But how can i get it by using pin code or postal code?
Below code worked for me
<?php
$zipcode="92604";
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$zipcode."&sensor=false";
$details=file_get_contents($url);
$result = json_decode($details,true);
$lat=$result['results'][0]['geometry']['location']['lat'];
$lng=$result['results'][0]['geometry']['location']['lng'];
echo "Latitude :" .$lat;
echo '<br>';
echo "Longitude :" .$lng;
?>
This worked for me:
$zip = 94043;
$site = file_get_contents('http://geocoder.ca/?postal='.$zip, false, NULL, 1000, 1000);
$goods = strstr($site, 'GPoint('); // cut off the first part up until
$end = strpos($goods, ')'); // the ending parenthesis of the coordinate
$cords = substr($goods, 7, $end - 7); // returns string with only the
$array = explode(', ',$cords); // convert string into array
echo "<pre>";
print_r($array); // output the array to verify
With the curl you can get lat and long from below code:
$zipcode=90012;
$url = "https://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($zipcode)."&sensor=false&key=XXXXXXXX";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
$search_data = json_decode($output);
$lat = $search_data->results[0]->geometry->location->lat;
$lng = $search_data->results[0]->geometry->location->lng;

Categories