Google Maps with PHP and Javascript

Posted: January 31, 2011 in Javascript, PHP5
Tags: ,

<?php

class GoogleMaps
{

var $APIKey = “ABQIAAAASTe3RGQOzgfE_7pgalxCWxTxwC-FTRouMUU4URT3KGgoa5PSihROzcGmVudxV_XFjm17uSpKPwoCYw”;

function SetLocation($Location)
{
$this->Location = $Location;
}
function SetWidth($Width)
{
$this->Width = $Width;
}
function SetHeight($Height)
{
$this->Height = $Height;
}
function DisplayGoogleMaps()
{
?>
<script src=”http://maps.google.com/maps?file=api&v=2&sensor=false&key=&lt;?php echo $this->APIKey; ?>” type=”text/javascript”></script>
<script type=”text/javascript”>
//var JobLocationInGoogleMaps = ‘Dhaka, BD’;
var JobLocationInGoogleMaps = ‘<?php echo $this->Location; ?>’;
if (GBrowserIsCompatible())
{
var geocoder = new GClientGeocoder();
geocoder.getLocations(JobLocationInGoogleMaps, function (locations)
{
if (locations.Placemark)
{
var north = locations.Placemark[0].ExtendedData.LatLonBox.north;
var south = locations.Placemark[0].ExtendedData.LatLonBox.south;
var east = locations.Placemark[0].ExtendedData.LatLonBox.east;
var west = locations.Placemark[0].ExtendedData.LatLonBox.west;

var bounds = new GLatLngBounds(new GLatLng(south, west), new GLatLng(north, east));
var map = new GMap2(document.getElementById(“GoogleMapCanvasHere”));
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
//map.addControl(new GSmallMapControl());
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addOverlay(new GMarker(bounds.getCenter()));
}
});
}
GUnload();
</script>
<div id=”GoogleMapCanvasHere” style=”width:<?php echo $this->Width; ?>px; height:<?php echo $this->Height; ?>px; background: url(./images/google-maps-loading.gif); background-repeat:no-repeat; background-position:center;”></div>
<?php
}
}

$maps = new GoogleMaps();
$maps->SetLocation(“Khulna,bd”); // Change Location
$maps->SetWidth(500); // Chaneg Map Width
$maps->SetHeight(350); // Change Map Height
$maps->DisplayGoogleMaps();

?>

<?php

function dateDiff($dformat, $endDate, $beginDate)
{
$split_endDate=split(” “,$endDate );
$split_beginDate=split(” “,$beginDate );

$date_parts1=explode($dformat, $split_beginDate[0]);
$date_parts2=explode($dformat, $split_endDate[0]);

$start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);

$end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);

return $days=$end_date – $start_date;
} //end of function

function yearcalculate($days)
{
$year=floor($days/365);
$monthday=$days%365;
$month=round($monthday/30);

if($year==0)
{
if($month==1)
{
$str=$month.” month”;
}
else if($month==0)
{
$str=”No experience”;
}
else
{
$str=$month.” month (s)”;
}
} //end of main if statement

else
{
if($year==1)
{

if($month==1)
{
$str=$year.” Year “.$month.” month”;
}
else if($month==0)
{
$str=$year.” Year”;
}
else
{
$str=$year.” Year “.$month.” month (s)”;
}

} //end of year=1 if statement

else
{
if($month==1)
{
$str=$year.” Year(s) “.$month.” month”;
}
else if($month==0)
{
$str=$year.” Year(s)”;
}
else
{
$str=$year.” Year(s)”.$month.” month (s)”;
}
}
} //end of main else statement
return $str;
} //end of yearcalculate function

$date1=”2010-10-27 00:00:00″;
$date2=”2011-01-25 00:00:00″;

$days=dateDiff(“-“, $date2, $date1);
echo $res=yearcalculate($days);

?>

Gmail rss feed with unread email in PHP

Posted: January 22, 2011 in PHP5
Tags:

<?php
$username = “gmail username”;
$password = “gmail password”;

// Initialise cURL
$c = curl_init(‘https://gmail.google.com/gmail/feed/atom&#8217;);

$headers = array(
“Host: gmail.google.com”,
“Authorization: Basic “.base64_encode($username.’:’.$password),
“User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4”,
“Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5”,
“Accept-Language: en-gb,en;q=0.5”,
“Accept-Encoding: text”,
“Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7”,
“Date: “.date(DATE_RFC822)
);

curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($c, CURLOPT_COOKIESESSION, true);
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($c, CURLOPT_UNRESTRICTED_AUTH, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 1);

$str = curl_exec($c);
echo $str;

curl_close($c);
?>

Conversion Of Binary Data To Image File In PHP

Posted: January 22, 2011 in PHP5
Tags:

< ?php
$con=file_get_contents(“tkdown.gif”);
$en=base64_encode($con);
$mime=’image/gif’;
$binary_data=’data:’ . $mime . ‘;base64,’ . $en ;
? >

<img src=”<?php echo $binary_data; ?>” alt=”Test”>

Image to Binary Conversion with PHP

Posted: January 22, 2011 in PHP5
Tags:

<?php

$content=file_get_contents(“tkdown.gif”);
$encode=base64_encode($content);

echo “Encoded Data:”.$encode;

?>

Get content from another site with Curl and PHP

Posted: January 20, 2011 in PHP5
Tags:

<?php
function get_string_between($string, $start, $end)
{
$string = ” “.$string;
$ini = strpos($string,$start);
if ($ini == 0)
return “”;
$ini += strlen($start);
$len = strpos($string,$end,$ini) – $ini;
return substr($string,$ini,$len);
}
//Initialize the Curl session
$ch = curl_init();

//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the URL
curl_setopt($ch, CURLOPT_URL,”http://www.dsebd.org/&#8221;);
//Execute the fetch
$data = curl_exec($ch);

echo $da=get_string_between($data,’imgs/topdown.gif”>’,’imgs/topdown.gif’);
//Close the connection
curl_close($ch);

?>

List all the users:

SELECT * FROM mysql.user;

Reset password;

UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';

RSS reader/RSS display with PHP

Posted: January 19, 2011 in PHP5
Tags:

<?php header(“Content-type: text/xml”); ?>
<?php echo “<?xml version=\”1.0\” encoding=\”UTF-8\”?>”; ?>
<rss version=”2.0″>
<channel>

<title>Website Title Here</title>

<?php
require_once(“controller/dbconfig.php”); //change database configuration file
$con=new data(); //change class name and put your class
$connect=$con->connect(); //change function name and put your class

$query = “select * from video1 where status=’2′ order by date desc limit 5”; //change the query
$result=$con->execute($query);

while ($line = mysql_fetch_assoc($result))
{
$return[] = $line;
}

?>
<?php foreach ($return as $item) { ?>

<item>
<title><?php echo htmlentities($item[‘v_name’]); ?></title> <!–Change table column name.[v_name] –>
<?php $id=$item[‘id’]; ?> <!–Change table column name.[id] –>
<link><?php echo “http://yoursite.com/video.php?id=$id&#8221;; ?></link>
<description>
<![CDATA[
<table width=”80%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=20%>
<img src=”<?php echo htmlentities($item[‘images’]); ?>” width=”80″ height=”80″ /> <!–Change table column name.[images] –>
</td>
<td width=80% valign=top><?php echo htmlentities($item[‘description’]);?></td> <!–Change table column name.[description] –>
</tr>

</table>

]]></description>
</item>

<?php } ?>

</channel>
</rss>

Incoming email read with php

Posted: January 19, 2011 in PHP5
Tags:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>

<style>
div.toggler { border:1px solid #ccc; background:url(gmail2.jpg) 10px 12px #eee no-repeat; cursor:pointer; padding:10px 32px; }
div.toggler .subject { font-weight:bold; }
div.read { color:#666; }
div.toggler .from, div.toggler .date { font-style:italic; font-size:11px; }
div.body { padding:10px 20px; }
</style>

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script&gt;
<script type=”text/javascript”>
$(document).ready(function(){
$(“.toggler “).click(function(){
$(“.body”).toggle();
});
});
</script>

</head>

<body>

<?php
ini_set(“max_execution_time”,360);

/* connect to server */
$hostname = ‘{domain.com:143/notls}INBOX’;
$username = ‘amit@domain.com’;
$password = ‘amitmondal’;

/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die(‘Cannot connect to domain:’ . imap_last_error());

/* grab emails */
$emails = imap_search($inbox,’ALL’);

/* if emails are returned, cycle through each… */
if($emails) {

$output = ”;

/* put the newest emails on top */
rsort($emails);

echo “Number of email:”.imap_num_msg($inbox);

/* for every email… */
foreach($emails as $email_number) {

$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,1);

$output.= ‘<div class=”toggler ‘.($overview[0]->seen ? ‘read’ : ‘unread’).'”>’;
$output.= ‘<span class=”subject”>’.$overview[0]->subject.'</span> ‘;
$output.= ‘<span class=”from”>’.$overview[0]->from.'</span>’;
$output.= ‘<span class=”date”>on ‘.$overview[0]->date.'</span>’;
$output.= ‘</div>’;

$output.= ‘<div class=”body”>’.$message.'</div>’;
} //end of for loop
echo $output;
} //end of if statement

/* close the connection */
imap_close($inbox);

?>

</body>
</html>

Read email from cpanel with imap in php

Posted: January 19, 2011 in PHP5
Tags:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>

<style>
div.toggler { border:1px solid #ccc; background:url(gmail2.jpg) 10px 12px #eee no-repeat; cursor:pointer; padding:10px 32px; }
div.toggler .subject { font-weight:bold; }
div.read { color:#666; }
div.toggler .from, div.toggler .date { font-style:italic; font-size:11px; }
div.body { padding:10px 20px; }
</style>

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script&gt;
<script type=”text/javascript”>
$(document).ready(function(){
$(“.toggler “).click(function(){
$(“.body”).toggle();
});
});
</script>

</head>

<body>

<?php
ini_set(“max_execution_time”,360);

/* connect to server */
$hostname = ‘{domain.com:143/notls}INBOX’;
$username = ‘amit@domain.com’;
$password = ‘amitmondal’;

/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die(‘Cannot connect to domain:’ . imap_last_error());

/* grab emails */
$emails = imap_search($inbox,’ALL’);

/* if emails are returned, cycle through each… */
if($emails) {

$output = ”;

/* put the newest emails on top */
rsort($emails);

echo “Number of email:”.imap_num_msg($inbox);

/* for every email… */
foreach($emails as $email_number) {

$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,1);

$output.= ‘<div class=”toggler ‘.($overview[0]->seen ? ‘read’ : ‘unread’).'”>’;
$output.= ‘<span class=”subject”>’.$overview[0]->subject.'</span> ‘;
$output.= ‘<span class=”from”>’.$overview[0]->from.'</span>’;
$output.= ‘<span class=”date”>on ‘.$overview[0]->date.'</span>’;
$output.= ‘</div>’;

$output.= ‘<div class=”body”>’.$message.'</div>’;
} //end of for loop
echo $output;
} //end of if statement

/* close the connection */
imap_close($inbox);

?>

</body>
</html>