0

I have the following code:

<HTML>
<?php

include('Net/SSH2.php');


$ssh = new Net_SSH2('my ip');
if (!$ssh->login('user', 'pass')){
		exit('Login Failed');
		}
$msisdn = $_POST['msisdn'];

$result = $ssh->exec('/usr/src/artsx/ash1.sh  '.$msisdn.'');



//echo $result; 
echo "<br>";

$array = explode(' ',$result);

//print_r($array);


$mcc = $array[0];
$mnc = $array[1];
$lac = $array[2];
$cell = $array[3];

//echo $mcc;
//echo $mnc;
//echo $lac;
//echo $cell;




$data = array(
"homeMobileCountryCode" => $mcc,
"homeMobileNetworkCode" => $mnc,
"radioType" => "gsm",
"cellTowers" => array( array(  
   "cellId" => $cell,
   "locationAreaCode" => $lac,
   "mobileCountryCode" => $mcc,
   "mobileNetworkCode" => $mnc
))
);


$url = "http://www.googleapis.com/geolocation/v1/geolocate?key=my_key";

function curl_get_contents($url)
{
	$ch = curl_init($url);
	curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch,CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, 0);
	$data = curl_exec($ch);
	curl_close($ch);
	return $data;
} 

print_r($data); 

$json = json_decode(curl_get_contents($url));

$options = array(
    	  'http' => array(
        'header'  => "Content-Type: application/json\r\n",
        'method'  => 'POST',
        'content' => json_encode($data),
    ),
);
print_r($json);


$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$result = json_decode($result,true);

echo $result;

$location=$result['location'];
$lat=$location['lat'];
$lng=$location['lng'];

//echo $lat;
echo "$lat $lng\n";

?>

And the response i receive is:

Warning: file_get_contents(http://www.googleapis.com/geolocation/v1/geolocate?key=my_key): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in D:\Apache24\htdocs\lookup\glookup.php on line 81.

Any ideas what can be the reason? I've already checked allow_url_fopen, and it is set to "On".

4

0 回答 0