Category Archives: PHP

Get latitude and longitude from address PHP

<?php
$country = “IN”;
$state = “Kerala”;
$city = “Kochi”;
$zipcode = “682030″;
$address = “PHPCodez”;

$query_string = “$country+$state+$city+$zipcode+$address”;
$address_encode = urlencode($query_string);
$geocode = ‘http://maps.google.com/maps/geo?q=’.$address_encode.’&output=json&sensor=false’;
$data = file_get_contents($geocode);
$output= json_decode($data);

if($output->Status->code == ’620′){
sleep(2);
$geocode = ‘http://maps.google.com/maps/geo?q=’.$address_encode.’&output=json&sensor=false’;
$data = file_get_contents($geocode);
$output= json_decode($data);
} elseif ($output->Status->code == ’602′){
$query_string = “$country+$state”;
$address_encode = urlencode($query_string);
$geocode = ‘http://maps.google.com/maps/geo?q=’.$address_encode.’&output=json&sensor=false’;
$data = file_get_contents($geocode);
$output= json_decode($data);
$longitude_long = $output->Placemark[0]->Point->coordinates[0];
$latitude_lat = $output->Placemark[0]->Point->coordinates[1];
if(($longitude_long == ”) && ($latitude_lat == ”)) {
$query_string = “$country”;
$address_encode = urlencode($query_string);
$geocode = ‘http://maps.google.com/maps/geo?q=’.$address_encode.’&output=json&sensor=false’;
$data = file_get_contents($geocode);
$output= json_decode($data);
}
}

echo $longitude = isset($output->Placemark[0]->Point->coordinates[0])?$output->Placemark[0]->Point->coordinates[0]:”;
echo $latitude = isset($output->Placemark[0]->Point->coordinates[1])?$output->Placemark[0]->Point->coordinates[1]:”;
?>

Short url bit.ly PHP

<?php
public function getBitlyUrl($url)
{

$version=”version=2.0.1”;
$login=”phpcodez”; // Replace with your login
$API=”phpcodez”;// Replace with your API
$bitly = ‘http://api.bit.ly/shorten?”.$version.”&longUrl=’.urlencode($url).’&login=”.$login.”&apiKey=”.$API.”&format=xml’;
$response = file_get_contents($bitly);
$xml = simplexml_load_string($response);
return ‘http://bit.ly/’.$xml->results->nodeKeyVal->hash;

}

?>

Completely disable any caching PHP

<?php
header(“Expires: Tue, 07 Aug 2000 08:00:00 GMT”);
header(“Last-Modified: ” . gmdate(“D, d M Y H:i:s”) . ” GMT”);
header(“Cache-Control: no-store, no-cache, must-revalidate, max-age=0″);
header(“Cache-Control: post-check=0, pre-check=0″, false);
header(“Pragma: no-cache”);
?>