<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sony AK Knowledge Center</title>
	<atom:link href="http://www.sony-ak.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sony-ak.com</link>
	<description>where tacit becomes explicit through codification</description>
	<lastBuildDate>Thu, 11 Mar 2010 16:51:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Posting Shoutout Message to Friendster using PHP and curl</title>
		<link>http://www.sony-ak.com/2010/03/posting-shoutout-message-to-friendster-using-php-and-curl/</link>
		<comments>http://www.sony-ak.com/2010/03/posting-shoutout-message-to-friendster-using-php-and-curl/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 16:44:56 +0000</pubDate>
		<dc:creator>Sony AK</dc:creator>
				<category><![CDATA[Curl]]></category>
		<category><![CDATA[Friendster]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[shoutout]]></category>
		<category><![CDATA[social network]]></category>
		<category><![CDATA[status]]></category>

		<guid isPermaLink="false">http://www.sony-ak.com/?p=576</guid>
		<description><![CDATA[Friendster (www.friendster.com) is one of popular social network in the internet. Through this short article we will demonstrate how to post shoutout message to your Friendster account using PHP and curl. Shoutout in Friendster is just like status message in Facebook. Here is the code to post the shoutout to Friendster.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
&#60;?php
  // set friendster [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/friendster-logo.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/friendster-logo-150x127.jpg" alt="" title="friendster-logo" style="border:1px solid #eee;" width="150" height="127" class="alignleft size-thumbnail wp-image-614" /></a>Friendster (<a href="http://www.friendster.com">www.friendster.com</a>) is one of popular social network in the internet. Through this short article we will demonstrate how to post shoutout message to your Friendster account using PHP and curl. Shoutout in Friendster is just like status message in Facebook. Here is the code to post the shoutout to Friendster.<span id="more-576"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// set friendster credentials</span>
  <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_friendster_username&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_friendster_password&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hi all, I update my shoutout using PHP and curl...&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// login to friendster</span>
  <span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;http://m.friendster.com/login/doLogin&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;btnLogIn=Log In&amp;email=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;password=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_ENCODING<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_COOKIEJAR<span style="color: #339933;">,</span> <span style="color: #990000;">getcwd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/cookies_friendster.cookie'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$curlData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// update your friendster shoutout</span>
  <span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;http://m.friendster.com/hp/editshoutout&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;btnSend=Post&amp;shoutout=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_ENCODING<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_COOKIEFILE<span style="color: #339933;">,</span> <span style="color: #990000;">getcwd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/cookies_friendster.cookie'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_COOKIEJAR<span style="color: #339933;">,</span> <span style="color: #990000;">getcwd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/cookies_friendster.cookie'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$curlData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Done!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Pretty simple, because we just emulate login to Friendster mobile version and update the shoutout message.</p>
<div id="attachment_612" class="wp-caption aligncenter" style="width: 664px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/friendster_shoutout.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/friendster_shoutout.jpg" alt="Sample of Friendster shoutout message" title="friendster_shoutout" width="654" height="294" class="size-full wp-image-612" /></a><p class="wp-caption-text">Sample of Friendster shoutout message</p></div>
<p>If you have any difficulty, please send comment below or drop us e-mail to info@sony-ak.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sony-ak.com/2010/03/posting-shoutout-message-to-friendster-using-php-and-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visualize Realtime USGS Earthquake Data using FusionCharts Free, PHP and Ajax (prototype.js)</title>
		<link>http://www.sony-ak.com/2010/03/visualize-realtime-usgs-earthquake-data-using-fusioncharts-free-php-and-ajax-prototype-js/</link>
		<comments>http://www.sony-ak.com/2010/03/visualize-realtime-usgs-earthquake-data-using-fusioncharts-free-php-and-ajax-prototype-js/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 08:13:44 +0000</pubDate>
		<dc:creator>Sony AK</dc:creator>
				<category><![CDATA[FusionCharts Free]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.sony-ak.com/?p=592</guid>
		<description><![CDATA[We will visualize the official earthquake data from U.S Geological Survey (USGS) into the chart using FusionCharts Free. USGS has earthquake feed is available on http://earthquake.usgs.gov/eqcenter/catalogs/eqs1day-M2.5.xml. We will feed this data and draw it into FusionCharts Free.
Since the data contains magnitude data and earthquake depth, then I choose to use Combination Charts (Column 2D + [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/usgs.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/usgs-150x72.jpg" alt="" title="usgs" width="150" height="72" style="border:1px solid #eee;" class="alignleft size-thumbnail wp-image-565" /></a>We will visualize the official earthquake data from U.S Geological Survey (USGS) into the chart using FusionCharts Free. USGS has earthquake feed is available on http://earthquake.usgs.gov/eqcenter/catalogs/eqs1day-M2.5.xml. We will feed this data and draw it into FusionCharts Free.<span id="more-592"></span></p>
<p>Since the data contains magnitude data and earthquake depth, then I choose to use Combination Charts (Column 2D + Line Dual Y) (FCF_MSColumn2DLineDY.swf). Why we use Dual Y Axis chart? Because we want to represent the earthquake magnitude on the primary Y axis and earthquake depth on secondary Y axis. We also utilizing prototype.js PeriodicalExecuter() class to make Ajax call to the earthquake data feed. By the time of this writing, we use FusionCharts Free v2.2.</p>
<p><strong>Important Notes</strong><br />
We assume you already familiar with deploying the FusionCharts Free and have experience using prototype.js, since we don&#8217;t explain every details of the tools we used in this article. Please refer to <a href="http://www.fusioncharts.com/free/docs">FusionCharts Free documentation</a> about deploying the chart and <a href="http://api.prototypejs.org/">prototype.js documentation</a> about the usage of the library.</p>
<p><strong>Prepare the chart and other requirements</strong><br />
First you must copy several file needed on this project.<br />
- You must copy FusionCharts.js to your web root folder.<br />
- You must copy prototype.js to your web root folder.<br />
- You must copy FCF_MSColumn2DLineDY.swf to your web root folder. </p>
<p><strong>Create the chart web page</strong><br />
Here is the code of the chart web page.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>US Geological Survey <span style="color: #339933;">-</span> Real<span style="color: #339933;">-</span><span style="color: #990000;">time</span><span style="color: #339933;">,</span> worldwide earthquake <span style="color: #990000;">list</span> <span style="color: #b1b100;">for</span> the past day<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;FusionCharts.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;prototype.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>body bgcolor<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#ffffff&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;earthQuakeContainer&quot;</span> align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;center&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">var</span> earthQuakeChart <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FusionCharts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;FCF_MSColumn2DLineDY.swf?XMLLoadingText=Retrieving data from U.S. Geological Survey. Please wait...&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;earthQuakeId&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;1000&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;500&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    earthQuakeChart<span style="color: #339933;">.</span>setDataURL<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'latest_earthquake_data.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    earthQuakeChart<span style="color: #339933;">.</span>render<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;earthQuakeContainer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">new</span> PeriodicalExecuter<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span> getLatestData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">new</span> Ajax<span style="color: #339933;">.</span>Request<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'latest_earthquake_data.php?anim=0'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
			  method<span style="color: #339933;">:</span> <span style="color: #0000ff;">'get'</span><span style="color: #339933;">,</span>
			  onSuccess<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>transport<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			    updateChartXML<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'earthQuakeId'</span><span style="color: #339933;">,</span> transport<span style="color: #339933;">.</span>responseText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			  <span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></pre></td></tr></table></div>

<p>Save it as earthquake.php.</p>
<p>You can see on above code, the script will call &#8216;latest_earthquake_data.php&#8217; on the first time and then will call the script again through Ajax call (using PeriodicalExecuter class on prototype.js) every 20 seconds. You can adjust the interval if you want.</p>
<p><strong>Prepare the script to feed the USGS earthquake data</strong><br />
Now here is the data feeder code (on latest_earthquake_data.php). This is the heart of this application and will supply the data to the FusionCharts.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// script name: latest_earthquake_data.php</span>
  <span style="color: #666666; font-style: italic;">// coder: Sony AK Knowledge Center - www.sony-ak.com</span>
&nbsp;
  <span style="color: #000088;">$animation</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'anim'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// define the feeds URL</span>
  <span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://earthquake.usgs.gov/earthquakes/catalogs/eqs1day-M2.5.xml&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$xmlDoc</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$xmlDoc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// start to iterate through the item nodes</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlDoc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;item&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$description</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;description&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$lat</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagNameNS</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.w3.org/2003/01/geo/wgs84_pos#&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;lat&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$long</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagNameNS</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.w3.org/2003/01/geo/wgs84_pos#&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;long&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$depth</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagNameNS</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://purl.org/dc/elements/1.1/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;subject&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//$depthValue = strstr($depth, &quot; &quot;, true);</span>
    <span style="color: #000088;">$depthValue</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$depth</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$depth</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$location</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;, &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;, &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$location</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&amp;apos;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$magnitude</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$xAxisLabelArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$description</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$xAxisLabel</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xAxisLabelArray</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$xAxisLabelArray</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$xAxisLabelArray</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;#10;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$xAxisLabelArray</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$xAxisLabelArray</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$country</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strrchr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;, &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;, &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$categoryArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;category name='&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$country</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$dataSetPrimaryArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;set value='&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$magnitude</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$dataSetSecondaryArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;set value='&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$depthValue</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'/&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000088;">$category</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$categoryArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$dataSetPrimary</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dataSetPrimaryArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$dataSetSecondary</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dataSetSecondaryArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$animation</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$animationParam</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$animationParam</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000088;">$xmlData</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;graph formatNumber='0' rotateNames='1' showValues='0' caption='U.S. Geological Survey (USGS) - Real-time, worldwide earthquake list for the past day' subCaption='Created by Sony AK Knowledge Center - www.sony-ak.com using FusionCharts Free' XAxisName='Country' PYAxisName='Magnitude (Richter)' SYAxisName='Depth (Km)' PYAxisMinValue='0' PYAxisMaxValue='10' SYAxisMinValue='0' animation='&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$animationParam</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;categories&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #000088;">$category</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;/categories&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;dataset seriesName='Magnitude' color='AFD8F8' parentYAxis='P'&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #000088;">$dataSetPrimary</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;/dataset&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;dataset seriesName='Depth' parentYAxis='S'&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #000088;">$dataSetSecondary</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;/dataset&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;/graph&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$xmlData</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Now you can try to run the &#8216;earthquake.php&#8217; from your web browser.</p>
<p>Here is the screen shot of the chart.</p>
<div id="attachment_608" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/usgs_fusioncharts_free.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/usgs_fusioncharts_free-300x144.jpg" alt="USGS Real-time worldwide earthquake data on FusionCharts Free" title="usgs_fusioncharts_free" width="300" height="144" class="size-medium wp-image-608" /></a><p class="wp-caption-text">USGS Real-time worldwide earthquake data on FusionCharts Free</p></div>
<p><strong>Live demo</strong><br />
If you want to see the demo, you can click <a href="http://www.sony-ak.com/usgsearthquakefusionchartsfree/earthquake.php">USGS Earthquake Realtime Data Chart</a>.</p>
<p>You can improve the code above and adjust with your requirements. The point is very easy to visualize real-world data using FusionCharts Free. If you have any difficulty, please send comment below or drop us e-mail to info@sony-ak.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sony-ak.com/2010/03/visualize-realtime-usgs-earthquake-data-using-fusioncharts-free-php-and-ajax-prototype-js/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sending E-mail using Telnet</title>
		<link>http://www.sony-ak.com/2010/03/sending-e-mail-using-telnet/</link>
		<comments>http://www.sony-ak.com/2010/03/sending-e-mail-using-telnet/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 07:38:33 +0000</pubDate>
		<dc:creator>Sony AK</dc:creator>
				<category><![CDATA[SMTP]]></category>
		<category><![CDATA[E-mail]]></category>
		<category><![CDATA[port 25]]></category>
		<category><![CDATA[protocol]]></category>
		<category><![CDATA[recipient]]></category>
		<category><![CDATA[simple mail transfer protocol]]></category>
		<category><![CDATA[telnet]]></category>

		<guid isPermaLink="false">http://www.sony-ak.com/?p=579</guid>
		<description><![CDATA[Back to 1998 when I was learning the SMTP protocol, that moment was very interesting for me to learn something new, one of fundamental protocol on the internet. You can read the details of the SMTP protocol here. SMTP stands for Simple Mail Transfer Protocol. Created by Jonathan B Postel, the objective is simple, to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/smtp.png"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/smtp-150x150.png" alt="" title="smtp" width="150" height="150" style="border:1px solid #eee;" class="alignleft size-thumbnail wp-image-590" /></a>Back to 1998 when I was learning the SMTP protocol, that moment was very interesting for me to learn something new, one of fundamental protocol on the internet. You can read the details of the <a href="http://www.ietf.org/rfc/rfc0821.txt">SMTP protocol here</a>. SMTP stands for Simple Mail Transfer Protocol. Created by Jonathan B Postel, the objective is simple, to transfer mail reliably and efficiently. The SMTP protocol still used today by many e-mail clients software.<span id="more-579"></span></p>
<p>Through this article, I will show you how to send simple e-mail using SMTP protocol. You will learn basic SMTP commands to send e-mail.</p>
<p>1. Open your command prompt window.</p>
<p>2. Type telnet [smtp host] [port 25], because I am using XL network, so I will use XL SMTP host. Their SMTP host is xlsmtp.xl.net.id. Standard port number for SMTP is 25. You can search your network SMTP host on the internet.</p>
<div id="attachment_580" class="wp-caption aligncenter" style="width: 451px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_connecting_smtp.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_connecting_smtp.jpg" alt="Connecting to XL SMTP host" title="xl_connecting_smtp" width="441" height="139" class="size-full wp-image-580" /></a><p class="wp-caption-text">Connecting to XL SMTP host</p></div>
<p>3. Type HELO or EHLO command. EHLO command is like HELO command but EHLO command will response with several SMTP abilities on that host.</p>
<div id="attachment_581" class="wp-caption aligncenter" style="width: 380px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_ehlo_smtp.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_ehlo_smtp.jpg" alt="Sending EHLO command" title="xl_ehlo_smtp" width="370" height="124" class="size-full wp-image-581" /></a><p class="wp-caption-text">Sending EHLO command</p></div>
<p>4. Type MAIL FROM command. This command is to define the sender e-mail address.</p>
<div id="attachment_582" class="wp-caption aligncenter" style="width: 334px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_mail_from_smtp.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_mail_from_smtp.jpg" alt="Sending MAIL FROM command with my e-mail address as a sender address" title="xl_mail_from_smtp" width="324" height="199" class="size-full wp-image-582" /></a><p class="wp-caption-text">Sending MAIL FROM command with my e-mail address as a sender address</p></div>
<p>5. Type RCPT TO command. This command is to define target or recipient e-mail address.</p>
<div id="attachment_584" class="wp-caption aligncenter" style="width: 398px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_rcpt_to_smtp.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_rcpt_to_smtp.jpg" alt="Send RCPT TO command" title="xl_rcpt_to_smtp" width="388" height="223" class="size-full wp-image-584" /></a><p class="wp-caption-text">Send RCPT TO command</p></div>
<p>6. Type DATA command. DATA command is to start input envelope part and body message part of your e-mail. What is envelope part? For example the e-mail header message that contains From, To, Subject and so on is called an envelope part of your e-mail, then there is single blank line that seperate the envelope data with the body e-mail message. Please see the sample below. At the end, just type single dot (.) command on a single line to finish the DATA command transaction.</p>
<div id="attachment_585" class="wp-caption aligncenter" style="width: 395px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_data_smtp.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_data_smtp.jpg" alt="Type DATA command" title="xl_data_smtp" width="385" height="243" class="size-full wp-image-585" /></a><p class="wp-caption-text">Type DATA command</p></div>
<div id="attachment_586" class="wp-caption aligncenter" style="width: 640px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_data_details_smtp.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_data_details_smtp.jpg" alt="Type the details of envelope part and body message part" title="xl_data_details_smtp" width="630" height="317" class="size-full wp-image-586" /></a><p class="wp-caption-text">Type the details of envelope part and body message part</p></div>
<div id="attachment_587" class="wp-caption aligncenter" style="width: 632px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_data_dot_smtp.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_data_dot_smtp.jpg" alt="Send the single dot (.) to end the DATA command transaction" title="xl_data_dot_smtp" width="622" height="322" class="size-full wp-image-587" /></a><p class="wp-caption-text">Send the single dot (.) to end the DATA command transaction</p></div>
<p>7. Type QUIT command to quit sending e-mail transaction and your message will be queued for delivery to the recipient address.</p>
<div id="attachment_588" class="wp-caption aligncenter" style="width: 639px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_quit_smtp.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/xl_quit_smtp.jpg" alt="Send QUIT command" title="xl_quit_smtp" width="629" height="334" class="size-full wp-image-588" /></a><p class="wp-caption-text">Send QUIT command</p></div>
<p>Simple isn&#8217;t? You can try yourself with your ISP SMTP server.</p>
<p>If you have any difficulty, please send comment below or drop us e-mail to info@sony-ak.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sony-ak.com/2010/03/sending-e-mail-using-telnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create Realtime USGS Earthquake Data Chart with FusionCharts using PHP and Ajax (prototype.js)</title>
		<link>http://www.sony-ak.com/2010/03/create-realtime-usgs-earthquake-data-chart-with-fusioncharts-using-php-and-ajax-prototype-js/</link>
		<comments>http://www.sony-ak.com/2010/03/create-realtime-usgs-earthquake-data-chart-with-fusioncharts-using-php-and-ajax-prototype-js/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 03:46:29 +0000</pubDate>
		<dc:creator>Sony AK</dc:creator>
				<category><![CDATA[FusionCharts]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[depth]]></category>
		<category><![CDATA[earth]]></category>
		<category><![CDATA[earthquake]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[gempa bumi]]></category>
		<category><![CDATA[magnitude]]></category>
		<category><![CDATA[period]]></category>
		<category><![CDATA[prototype.js]]></category>
		<category><![CDATA[richter]]></category>
		<category><![CDATA[us geological survey]]></category>
		<category><![CDATA[usgs]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.sony-ak.com/?p=537</guid>
		<description><![CDATA[Fortunately we have time to play with FusionCharts again. Now we will playing with real-world case. We will visualize the official earthquake data from U.S Geological Survey (USGS) into the chart using FusionCharts. I am using FusionCharts Developer licence in this case. USGS has earthquake feed on http://earthquake.usgs.gov/eqcenter/catalogs/eqs1day-M2.5.xml. We will feed this data and draw [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/usgs.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/usgs-150x72.jpg" alt="" title="usgs" width="150" height="72" style="border:1px solid #eee;" class="alignleft size-thumbnail wp-image-565" /></a>Fortunately we have time to play with FusionCharts again. Now we will playing with real-world case. We will visualize the official earthquake data from U.S Geological Survey (USGS) into the chart using FusionCharts. I am using FusionCharts Developer licence in this case. USGS has earthquake feed on http://earthquake.usgs.gov/eqcenter/catalogs/eqs1day-M2.5.xml. We will feed this data and draw it into FusionCharts.<span id="more-537"></span></p>
<p>Since the data contains magnitude data and earthquake depth, then I choose to use Scroll Combination (Dual Y Axis) 2D chart (ScrollCombiDY2D.swf). Why we use Dual Y Axis chart? Because we want to represent the earthquake magnitude on the primary Y axis and earthquake depth on secondary Y axis. Because there are many data on the earthquake feed, so we use the scrolled version of the chart. We also utilizing prototype.js PeriodicalExecuter() class to make Ajax call to the earthquake data feed. By the time of this writing, we use FusionCharts v3.1 (developer license), Release: 24th February 2009.</p>
<p><strong>Important Notes</strong><br />
We assume you already familiar with deploying the FusionCharts v3 and have experience using prototype.js, since we don&#8217;t explain every details of the tools we used in this article. Please refer to <a href="http://www.fusioncharts.com/docs">FusionCharts documentation</a> about deploying the chart and <a href="http://api.prototypejs.org/">prototype.js documentation</a> about the usage of the library.</p>
<p><strong>Prepare the chart and other requirements</strong><br />
First you must copy several file needed on this project.<br />
- You must copy FusionCharts.js to your web root folder.<br />
- You must copy prototype.js to your web root folder.<br />
- You must copy ScrollCombiDY2D.swf to your web root folder. </p>
<p><strong>Create the chart web page</strong><br />
Here is the code of the chart web page.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>US Geological Survey <span style="color: #339933;">-</span> Real<span style="color: #339933;">-</span><span style="color: #990000;">time</span><span style="color: #339933;">,</span> worldwide earthquake <span style="color: #990000;">list</span> <span style="color: #b1b100;">for</span> the past day<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;FusionCharts.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;prototype.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>body bgcolor<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#ffffff&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;earthQuakeContainer&quot;</span> align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;center&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	    <span style="color: #000000; font-weight: bold;">var</span> earthQuakeChart <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FusionCharts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ScrollCombiDY2D.swf?XMLLoadingText=Retrieving data from U.S. Geological Survey. Please wait...&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;earthQuakeId&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;1000&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;500&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    earthQuakeChart<span style="color: #339933;">.</span>setDataURL<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'latest_earthquake_data.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    earthQuakeChart<span style="color: #339933;">.</span>render<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;earthQuakeContainer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">new</span> PeriodicalExecuter<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span> getLatestData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">new</span> Ajax<span style="color: #339933;">.</span>Request<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'latest_earthquake_data.php?anim=0'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
			  method<span style="color: #339933;">:</span> <span style="color: #0000ff;">'get'</span><span style="color: #339933;">,</span>
			  onSuccess<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>transport<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			    <span style="color: #666666; font-style: italic;">// updateChartXML only applies for FusionCharts Free</span>
			    <span style="color: #666666; font-style: italic;">//updateChartXML('earthQuakeId', transport.responseText);</span>
			    <span style="color: #000000; font-weight: bold;">var</span> chartObj <span style="color: #339933;">=</span> getChartFromId<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;earthQuakeId&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  			chartObj<span style="color: #339933;">.</span>setDataXML<span style="color: #009900;">&#40;</span>transport<span style="color: #339933;">.</span>responseText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			  <span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></pre></td></tr></table></div>

<p>Save it as earthquake.php.</p>
<p>You can see on above code, the script will call &#8216;latest_earthquake_data.php&#8217; on the first time and then will call the script again through Ajax call (using PeriodicalExecuter class on prototype.js) every 20 seconds. You can adjust the interval if you want.</p>
<p><strong>Prepare the script to feed the USGS earthquake data</strong><br />
Now here is the data feeder code (on latest_earthquake_data.php). This is the heart of this application and will supply the data to the FusionCharts.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// script name: latest_earthquake_data.php</span>
  <span style="color: #666666; font-style: italic;">// coder: Sony AK Knowledge Center - www.sony-ak.com</span>
&nbsp;
  <span style="color: #000088;">$animation</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'anim'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// define the feeds URL</span>
  <span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://earthquake.usgs.gov/earthquakes/catalogs/eqs1day-M2.5.xml&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$xmlDoc</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$xmlDoc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// start to iterate through the item nodes</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlDoc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;item&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$description</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;description&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$lat</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagNameNS</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.w3.org/2003/01/geo/wgs84_pos#&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;lat&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$long</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagNameNS</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.w3.org/2003/01/geo/wgs84_pos#&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;long&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$depth</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagNameNS</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://purl.org/dc/elements/1.1/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;subject&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// $depthValue = strstr($depth, &quot; &quot;, true); // for PHP 5.3.0</span>
    <span style="color: #000088;">$depthValue</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$depth</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$depth</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$location</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;, &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;, &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$location</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&amp;apos;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$magnitude</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$xAxisLabelArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$description</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$xAxisLabel</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xAxisLabelArray</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$xAxisLabelArray</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$xAxisLabelArray</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;#10;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$xAxisLabelArray</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$xAxisLabelArray</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$country</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strrchr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;, &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;, &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$categoryArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;category label='&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$xAxisLabel</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;#10;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$country</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;' /&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$dataSetPrimaryArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;set value='&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$magnitude</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;' toolText='Magnitude: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$magnitude</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;{br}Location: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$location</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;{br}Date: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$description</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$dataSetSecondaryArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;set value='&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$depthValue</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;' displayValue='&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$depthValue</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; km'/&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000088;">$category</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$categoryArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$dataSetPrimary</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dataSetPrimaryArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$dataSetSecondary</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dataSetSecondaryArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$animation</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$animationParam</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$animationParam</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000088;">$xmlData</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;chart palette='2' caption='U.S. Geological Survey (USGS)' subCaption='Real-time, worldwide earthquake list for the past day&amp;#10;Created by Sony AK Knowledge Center - www.sony-ak.com using FusionCharts v3' XAxisName='Date and Country' PYAxisName='Magnitude (Richter)' SYAxisName='Depth (Km)' numVisiblePlot='7' useRoundEdges='1' PYAxisMinValue='0' PYAxisMaxValue='10' SYAxisMinValue='0' canvasPadding='60' animation='&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$animationParam</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;categories&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #000088;">$category</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;/categories&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;dataset seriesName='Magnitude' renderAs='Line' parentYAxis='P'&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #000088;">$dataSetPrimary</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;/dataset&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;dataset seriesName='Depth' parentYAxis='S' renderAs='Area'&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #000088;">$dataSetSecondary</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;/dataset&gt;&quot;</span> <span style="color: #339933;">.</span>
             <span style="color: #0000ff;">&quot;&lt;/chart&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$xmlData</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Now you can try to run the &#8216;earthquake.php&#8217; from your web browser.</p>
<p>Here is the screen shot of the chart.</p>
<div id="attachment_563" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/usgs_earthquake_fusioncharts.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/usgs_earthquake_fusioncharts-300x150.jpg" alt="USGS earthquake data on FusionCharts" title="usgs_earthquake_fusioncharts" width="300" height="150" class="size-medium wp-image-563" /></a><p class="wp-caption-text">USGS earthquake data on FusionCharts</p></div>
<p><strong>Live demo</strong><br />
If you want to see the demo, you can click <a href="http://www.sony-ak.com/usgsearthquakefusioncharts/earthquake.php">USGS Earthquake Realtime Data Chart</a>.</p>
<p>You can improve the code above and adjust with your requirements. The point is very easy to visualize real-world data using FusionCharts. If you have any difficulty, please send comment below or drop us e-mail to info@sony-ak.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sony-ak.com/2010/03/create-realtime-usgs-earthquake-data-chart-with-fusioncharts-using-php-and-ajax-prototype-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connect to IRC (Internet Relay Chat) Network using Telnet</title>
		<link>http://www.sony-ak.com/2010/03/connect-to-irc-internet-relay-chat-network-using-telnet/</link>
		<comments>http://www.sony-ak.com/2010/03/connect-to-irc-internet-relay-chat-network-using-telnet/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 04:14:31 +0000</pubDate>
		<dc:creator>Sony AK</dc:creator>
				<category><![CDATA[IRC]]></category>
		<category><![CDATA[chat]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[internet relay chat]]></category>
		<category><![CDATA[protocol]]></category>
		<category><![CDATA[rfc]]></category>
		<category><![CDATA[rfc 1459]]></category>
		<category><![CDATA[telnet]]></category>

		<guid isPermaLink="false">http://www.sony-ak.com/?p=548</guid>
		<description><![CDATA[In the past days, IRC is very popular chat network in the world. Many people using it to chat with friends over the world. Nowdays IRC is less popular than other services, such Yahoo! Messenger, Skype, Gtalk, Facebook Chat etc, but IRC still used on some community such as developer community. For example, CakePHP community [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/irc.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/irc-150x150.jpg" alt="" title="irc" width="150" height="150" style="border:1px solid #eee;" class="alignleft size-thumbnail wp-image-555" /></a>In the past days, IRC is very popular chat network in the world. Many people using it to chat with friends over the world. Nowdays IRC is less popular than other services, such Yahoo! Messenger, Skype, Gtalk, Facebook Chat etc, but IRC still used on some community such as developer community. For example, CakePHP community often available on irc.freenode.net #cakephp, CodeIgniter also available on the same server at #codeigniter.</p>
<p>Now we will try to do fun things. Yes, we will simulate connection to IRC server not using IRC client software but only using Telnet. Again, this is for personal fun things. I just do it for remembering the past when learning the <a href="http://www.faqs.org/rfcs/rfc1459.html">IRC protocol</a>.<span id="more-548"></span></p>
<p><strong>Let&#8217;s start baby</strong><br />
1. Define the IRC server to connect. I choose irc.freenode.net on port 6666 since it&#8217;s very popular IRC network now. Go to command prompt and type the following command.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;">telnet irc.freenode.net <span style="color: #cc66cc;">6666</span></pre></td></tr></table></div>

<div id="attachment_549" class="wp-caption aligncenter" style="width: 425px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/irc_connect.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/irc_connect.jpg" alt="Connect to irc.freenode.net port 6666" title="irc_connect" width="415" height="164" class="size-full wp-image-549" /></a><p class="wp-caption-text">Connect to irc.freenode.net port 6666</p></div>
<p>2. You will be connected to IRC server irc.freenode.net network. Now you must define your nickname. Type this command to define your nickname.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;">NICK sonyarianto</pre></td></tr></table></div>

<div id="attachment_550" class="wp-caption aligncenter" style="width: 567px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/irc_define_nickname.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/irc_define_nickname.jpg" alt="Define nickname" title="irc_define_nickname" width="557" height="128" class="size-full wp-image-550" /></a><p class="wp-caption-text">Define nickname</p></div>
<p>3. Now you must send the USER command. It is used in communication between servers to indicate new user arriving on IRC, since only after both USER and NICK have been received from a client does a user become registered. The syntax is like this &#8220;USER <username> <hostname> <servername> <realname>&#8220;. Just type like the following.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;">USER sonyarianto host server :<span style="color: #b100b1; font-weight: bold;">Sony AK IRC Mania</span></pre></td></tr></table></div>

<div id="attachment_551" class="wp-caption aligncenter" style="width: 573px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/irc_type_user.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/irc_type_user.jpg" alt="Typing USER command to IRC" title="irc_type_user" width="563" height="147" class="size-full wp-image-551" /></a><p class="wp-caption-text">Typing USER command to IRC</p></div>
<p>4. You will get many lines on your screen, don&#8217;t worry, it&#8217;s called MOTD (Message Of The Day) string. Now you are already connected to irc.freenode.net IRC network.</p>
<p>5. Now we will simulate to join a IRC channel. I will join to #codeigniter channel. Type the following command to join a channel.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;">JOIN #codeigniter</pre></td></tr></table></div>

<p>6. Now you already joined to #codeigniter channel. There are many string on your screen, don&#8217;t worry, it&#8217;s a list of users that also connected to #codeigniter channel.</p>
<div id="attachment_552" class="wp-caption aligncenter" style="width: 719px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/irc_channel_users.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/irc_channel_users.jpg" alt="After join to #codeigniter channel" title="irc_channel_users" width="709" height="206" class="size-full wp-image-552" /></a><p class="wp-caption-text">After join to #codeigniter channel</p></div>
<p>You can see on above screen shot, there are sonyarianto, bwoodall, techrush, Hutch[S] etc, it is users that connected to #codeigniter channel.</p>
<p>7. Now you can send message to #codeigniter with PRIVMSG command. Type the following command.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;">PRIVMSG #codeigniter :<span style="color: #b100b1; font-weight: bold;">Hi everybody, how r u today?</span></pre></td></tr></table></div>

<div id="attachment_554" class="wp-caption aligncenter" style="width: 640px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/irc_privmsg_to_channel.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/irc_privmsg_to_channel.jpg" alt="Send command to channel with PRIVMSG" title="irc_privmsg_to_channel" width="630" height="152" class="size-full wp-image-554" /></a><p class="wp-caption-text">Send command to channel with PRIVMSG</p></div>
<p>8. The PRIVMSG command also can be used to send message to a user. The syntax is like this &#8216;PRIVMSG <user> :<message>&#8216;. Let&#8217;s assume there user with nick &#8216;agus&#8217; so you can type message privately to agus using this way.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;">PRIVMSG agus :<span style="color: #b100b1; font-weight: bold;">Hello Agus, I'm here to chat with you.</span></pre></td></tr></table></div>

<p>9. That&#8217;s all. Now  you have learned basic commands on IRC protocol. To quit from a channel you can use PART command.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;">PART #codeigniter</pre></td></tr></table></div>

<p>You will left from #codeigniter channel.</p>
<p>10. To quit from IRC network you can use QUIT command.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;">QUIT</pre></td></tr></table></div>

<p>That&#8217;s all, now I hope you will understand basic knowledge command about IRC protocol and from this point you can improve your knowledge if you want to create IRC application or IRC robot.</p>
<p>If you have any difficulty, please send comment below or drop us e-mail to info@sony-ak.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sony-ak.com/2010/03/connect-to-irc-internet-relay-chat-network-using-telnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Google Apps Provisioning API with Zend Framework Gdata Class to Manipulate User Account</title>
		<link>http://www.sony-ak.com/2010/03/using-google-apps-provisioning-api-with-zend-framework-gdata-class-to-manipulate-user-account/</link>
		<comments>http://www.sony-ak.com/2010/03/using-google-apps-provisioning-api-with-zend-framework-gdata-class-to-manipulate-user-account/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 09:35:20 +0000</pubDate>
		<dc:creator>Sony AK</dc:creator>
				<category><![CDATA[Google Apps]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google apps provisioning api]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[zend_gdata]]></category>

		<guid isPermaLink="false">http://www.sony-ak.com/?p=534</guid>
		<description><![CDATA[Playing with APIs on other web service is always fun. Now we will talking about utilizing the Zend Framework&#8217;s Zend_Gdata class to manipulate user account on your Google Apps account. Nowdays there many people or institutions using Google Apps as their e-mail solutions. If you are using Google Apps Premier Edition and Google Apps Education [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/google_apps.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/google_apps-150x150.jpg" style="border:1px solid #eee;" alt="" title="google_apps" width="150" height="150" class="alignleft size-thumbnail wp-image-540" /></a>Playing with APIs on other web service is always fun. Now we will talking about utilizing the Zend Framework&#8217;s Zend_Gdata class to manipulate user account on your Google Apps account. Nowdays there many people or institutions using Google Apps as their e-mail solutions. If you are using <strong>Google Apps Premier Edition</strong> and <strong>Google Apps Education Edition</strong> you will have access to Google Provisioning API. To enable the API, log in to your admin account, and click the Users and groups  tab. Then click the Settings subtab, select the checkbox to enable the Provisioning API and save your changes. (You will need to complete the steps for setting up Google Apps before you can log in to your admin account.)<span id="more-534"></span></p>
<p><strong>What is actually Google Apps Provisioning API?</strong><br />
Google Apps allows website administrators to offer a variety of personalized and co-branded Google applications, such as Gmail. Google Apps Provisioning API enables application developers to programmatically enable access to these applications. Specifically, the API provides functions for creating, retrieving, updating and deleting user accounts, nicknames and email groups. You can access more information about Google Apps Provisioning API on their <a href="http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html">official documentation page</a>.</p>
<p><strong>Let&#8217;s start</strong><br />
Fortunately I have a <strong>Google Apps Partner Edition</strong> from the past days for one of my domain, mobitrek.com. So I will use this as our simulation to implement the Google Apps Provisioning API. Before using the Provisioning API, you will need an administrator username and password for your Google Apps domain.</p>
<p>We not cover all complicated things over the API, but will will show you some example to to simple task such as creating user. The complete reference already available on <a href="http://framework.zend.com/manual/en/zend.gdata.gapps.html">http://framework.zend.com/manual/en/zend.gdata.gapps.html</a> and <a href="http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference_php.html">http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference_php.html</a>.</p>
<p><strong>Authenticating to your Google Apps domain</strong><br />
Before you call some Google Apps Provisioning API, you have to do authentication process to your domain. Here is the way to do it.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Loader.php'</span><span style="color: #339933;">;</span>
  Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Gdata_ClientLogin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Gdata_Gapps'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// google apps credentials</span>
  <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_administrator_email_on_your_google_apps_domain&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// example sony@domain.com</span>
  <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_google_apps_domain_password&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$domain</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your-domain.com&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> Zend_Gdata_ClientLogin<span style="color: #339933;">::</span><span style="color: #004000;">getHttpClient</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> Zend_Gdata_Gapps<span style="color: #339933;">::</span><span style="color: #004000;">AUTH_SERVICE_NAME</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$service</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_Gapps<span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">,</span> <span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Now we will try to create e-mail account on your Google Apps domain.</p>
<p><strong>Create new user</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Loader.php'</span><span style="color: #339933;">;</span>
  Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Gdata_ClientLogin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Gdata_Gapps'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// google apps credentials</span>
  <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_administrator_email_on_your_google_apps_domain&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// example sony@domain.com</span>
  <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_google_apps_domain_password&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$domain</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your-domain.com&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// do authenticate to Google Apps domain</span>
  <span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> Zend_Gdata_ClientLogin<span style="color: #339933;">::</span><span style="color: #004000;">getHttpClient</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> Zend_Gdata_Gapps<span style="color: #339933;">::</span><span style="color: #004000;">AUTH_SERVICE_NAME</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$service</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_Gapps<span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">,</span> <span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// create new user</span>
  <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;esa.ivani&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$givenName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Esa&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$familyName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Ivani&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;welcome&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$service</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createUser</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$givenName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$familyName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$passwordHashFunction</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$quota</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;done!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>We create new user &#8216;esa.ivani&#8217; on example above. We assume that user &#8216;esa.ivani&#8217; is not exists yet. How to detect if user already exists during user creation process? It&#8217;s easy, there is methods for handling error for above condition. Here is the sample code again based on code above.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Loader.php'</span><span style="color: #339933;">;</span>
  Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Gdata_ClientLogin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Gdata_Gapps'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// google apps credentials</span>
  <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_administrator_email_on_your_google_apps_domain&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// example sony@domain.com</span>
  <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_google_apps_domain_password&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$domain</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your-domain.com&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// do authenticate to Google Apps domain</span>
  <span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> Zend_Gdata_ClientLogin<span style="color: #339933;">::</span><span style="color: #004000;">getHttpClient</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> Zend_Gdata_Gapps<span style="color: #339933;">::</span><span style="color: #004000;">AUTH_SERVICE_NAME</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$service</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_Gapps<span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">,</span> <span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// create new user</span>
  <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;esa.ivani&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$givenName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Esa&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$familyName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Ivani&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;welcome&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  try<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$service</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createUser</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$givenName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$familyName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$passwordHashFunction</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$quota</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Zend_Gdata_Gapps_ServiceException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasError</span><span style="color: #009900;">&#40;</span>Zend_Gdata_Gapps_Error<span style="color: #339933;">::</span><span style="color: #004000;">ENTITY_EXISTS</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;User already exists!&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getErrors</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Error encountered: {<span style="color: #006699; font-weight: bold;">$error-&gt;getReason</span>()} ({<span style="color: #006699; font-weight: bold;">$error-&gt;getErrorCode</span>()})<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;done!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>We put the &#8216;createUser&#8217; method inside the ServiceException. The PHP client library will throw a ServiceException when it receives an error response from the Provisioning API. Other types of exceptions may also be thrown for other types of errors. To process or log a ServiceException, retrieve the error array by calling the $e->getErrors() method, then calling $error->getErrorCode()  or $error->getReason() on each element of that array to determine the type of errors that the Provisioning API returned. The presence of individual error codes can also quickly be determined by calling $e->hasError($errorCode).</p>
<p><strong>Retrieve User</strong><br />
You can call retrieveUser() method to get details about particular user. Here is the sample code.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// to authenticate to Google Apps</span>
  <span style="color: #666666; font-style: italic;">// use sample above</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// retrieve user details</span>
  <span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$service</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">retrieveUser</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span>  <span style="color: #0000ff;">'Username: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">login</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">userName</span>  <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span>  <span style="color: #0000ff;">'Given Name: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">givenName</span>  <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span>  <span style="color: #0000ff;">'Family Name: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">familyName</span>  <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span>  <span style="color: #0000ff;">'Suspended: '</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">login</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">suspended</span> ? <span style="color: #0000ff;">'Yes'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'No'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Admin: '</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">login</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">admin</span> ? <span style="color: #0000ff;">'Yes'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'No'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Must Change Password: '</span> <span style="color: #339933;">.</span>
     <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">login</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">changePasswordAtNextLogin</span> ? <span style="color: #0000ff;">'Yes'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'No'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Has Agreed To Terms: '</span> <span style="color: #339933;">.</span>
     <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">login</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">agreedToTerms</span> ? <span style="color: #0000ff;">'Yes'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'No'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>There are many methods you can utilize to access Google Apps Provisioning API. From creating user, update user, retrieve user, delete user, suspend user, restore suspend user and also nickname management. The point is, <strong>you can create your own email registration service with this API with provide seemless integration with your web application or service</strong>. Please read again the manual at the URLs below.</p>
<p>- <a href="http://framework.zend.com/manual/en/zend.gdata.gapps.html">http://framework.zend.com/manual/en/zend.gdata.gapps.html</a><br />
- <a href="http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference_php.html">http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference_php.html</a></p>
<p>If you have any difficulty, please send comment below or drop us e-mail to info@sony-ak.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sony-ak.com/2010/03/using-google-apps-provisioning-api-with-zend-framework-gdata-class-to-manipulate-user-account/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Access to Unread Gmail Messages using Gmail&#8217;s Atom Feed and PHP</title>
		<link>http://www.sony-ak.com/2010/03/access-to-unread-gmail-messages-using-gmails-atom-feed-and-php/</link>
		<comments>http://www.sony-ak.com/2010/03/access-to-unread-gmail-messages-using-gmails-atom-feed-and-php/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 03:30:02 +0000</pubDate>
		<dc:creator>Sony AK</dc:creator>
				<category><![CDATA[Gmail]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[atom]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[E-mail]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[zend_http_client]]></category>

		<guid isPermaLink="false">http://www.sony-ak.com/?p=512</guid>
		<description><![CDATA[One of our readers ask me about Gmail API availability. Yes, right now there is no Gmail API from Google. They only provide Gmail Atom Feed to get the unread messages from a particular Gmail user account. How to do that? Here is the simple code using PHP libcurl and Zend_Http_Client class.
Access to the Gmail&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/gmail.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/gmail.jpg" alt="" title="gmail" width="128" height="128" style="border:1px solid #eee;" class="alignleft size-full wp-image-526" /></a>One of our readers ask me about Gmail API availability. Yes, right now there is no Gmail API from Google. They only provide Gmail Atom Feed to get the unread messages from a particular Gmail user account. How to do that? Here is the simple code using PHP libcurl and Zend_Http_Client class.<span id="more-512"></span></p>
<p>Access to the Gmail&#8217;s Atom Feed will be using HTTP Basic Authentication.</p>
<p><strong>Using PHP libcurl</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// script name: gmail_atom_feed_curl.php</span>
  <span style="color: #666666; font-style: italic;">// coder: Sony AK Knowledge Center - www.sony-ak.com</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// your Gmail credentials</span>
  <span style="color: #000088;">$gmailUsername</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_gmail_username&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$gmailPassword</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_gmail_password&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// do access to Gmail's Atom Feed using curl</span>
  <span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;https://mail.google.com/mail/feed/atom/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_USERPWD<span style="color: #339933;">,</span> <span style="color: #000088;">$gmailUsername</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$gmailPassword</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_HTTPAUTH<span style="color: #339933;">,</span> CURLBASIC_AUTH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_ENCODING<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$curlData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$curlData</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Here is the sample result on Firefox.</p>
<div id="attachment_523" class="wp-caption aligncenter" style="width: 673px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/02/gmail_atom_feed.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/02/gmail_atom_feed.jpg" alt="Sample of Gmail Atom Feed on Firefox" title="gmail_atom_feed" width="663" height="517" class="size-full wp-image-523" /></a><p class="wp-caption-text">Sample of Gmail Atom Feed on Firefox</p></div>
<p><strong>Using Zend Framework (Zend_Http_Client class)</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// script name: gmail_atom_feed_zf.php</span>
  <span style="color: #666666; font-style: italic;">// coder: Sony AK Knowledge Center - www.sony-ak.com</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// load the ZF class loader</span>
  <span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Loader.php'</span><span style="color: #339933;">;</span>
&nbsp;
  Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Http_Client'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// your Gmail credentials</span>
  <span style="color: #000088;">$gmailUsername</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_gmail_username&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$gmailPassword</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_gmail_password&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Http_Client<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'https://mail.google.com/mail/feed/atom/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAuth</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gmailUsername</span><span style="color: #339933;">,</span> <span style="color: #000088;">$gmailPassword</span><span style="color: #339933;">,</span> Zend_Http_Client<span style="color: #339933;">::</span><span style="color: #004000;">AUTH_BASIC</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// get the body response</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBody</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>There is nice information inside this feed. You can find number of unread Gmail messages on the tag below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fullcount<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>number of messages<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fullcount<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<div id="attachment_532" class="wp-caption aligncenter" style="width: 577px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/03/number_of_unread_messages.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/03/number_of_unread_messages.jpg" alt="Number of unread messages on Gmail&#039;s Atom Feed" title="number_of_unread_messages" width="567" height="88" class="size-full wp-image-532" /></a><p class="wp-caption-text">Number of unread messages on Gmail's Atom Feed</p></div>
<p>This Gmail&#8217;s Atom Feed only provides you with the latest 20 messages. They don&#8217;t provide paging mechanism on the feed as stated on <a href="http://tools.ietf.org/html/rfc5005">RFC 5005</a>. But no problem, you can found this handy if you want to create a simple new messages notification application.</p>
<p>If you have any difficulty, please send comment below or drop us e-mail to info@sony-ak.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sony-ak.com/2010/03/access-to-unread-gmail-messages-using-gmails-atom-feed-and-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Use Zend Framework without Editing php.ini File?</title>
		<link>http://www.sony-ak.com/2010/02/how-to-use-zend-framework-without-editing-php-ini-file/</link>
		<comments>http://www.sony-ak.com/2010/02/how-to-use-zend-framework-without-editing-php-ini-file/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 00:17:45 +0000</pubDate>
		<dc:creator>Sony AK</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[ini_set]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[path]]></category>
		<category><![CDATA[path_separator]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[zf]]></category>

		<guid isPermaLink="false">http://www.sony-ak.com/?p=515</guid>
		<description><![CDATA[After reading the How to Install Zend Framework? article, some of the reader asking about how to use Zend Framework without editing the php.ini file. Yes, good question. Actually there is another way to achive this. You can use the ini_set() function to set the value on your PHP configuration option. Here is the sample [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sony-ak.com/wp-content/uploads/2010/02/zend-framework.png"><img src="http://www.sony-ak.com/wp-content/uploads/2010/02/zend-framework-150x150.png" style="border:1px solid #eee;" alt="" title="zend-framework" width="150" height="150" class="alignleft size-thumbnail wp-image-463" /></a>After reading the <a href="http://www.sony-ak.com/2010/02/how-to-install-zend-framework/">How to Install Zend Framework?</a> article, some of the reader asking about how to use Zend Framework without editing the php.ini file. Yes, good question. Actually there is another way to achive this. You can use the ini_set() function to set the value on your PHP configuration option. Here is the sample of using ini_set() to change the value of &#8216;include_path&#8217; on your PHP configuration.<span id="more-515"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// add the ZF library folder to include_path (on the top of the script)</span>
  <span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;include_path&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">ini_get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'include_path'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PATH_SEPARATOR <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;your_zend_framework_library_full_path&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// ini_set(&quot;include_path&quot;, ini_get('include_path') . PATH_SEPARATOR . &quot;C:\master\frameworks\ZendFramework-1.10.1\library&quot;);</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// your code here</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>Notes:</strong><br />
The configuration option will keep this new value during the script&#8217;s execution, and will be restored at the script&#8217;s ending.</p>
<p>If you have any difficulty, please send comment below or drop us e-mail to info@sony-ak.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sony-ak.com/2010/02/how-to-use-zend-framework-without-editing-php-ini-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update Status on LinkedIn using PHP</title>
		<link>http://www.sony-ak.com/2010/02/update-status-on-linkedin-using-php/</link>
		<comments>http://www.sony-ak.com/2010/02/update-status-on-linkedin-using-php/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 18:32:10 +0000</pubDate>
		<dc:creator>Sony AK</dc:creator>
				<category><![CDATA[Curl]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[linkedin.com]]></category>
		<category><![CDATA[professional]]></category>
		<category><![CDATA[professional social network]]></category>
		<category><![CDATA[social network]]></category>

		<guid isPermaLink="false">http://www.sony-ak.com/?p=501</guid>
		<description><![CDATA[LinkedIn (www.linkedin.com) is one of the famous professional social network in the world. They connect many professionals around the world through their network. One of nice feature on LinkedIn is you can update status message. They called it &#8216;What are you working on?&#8217;. Here is simple PHP code that can update status message on your [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sony-ak.com/wp-content/uploads/2010/02/linkedin1.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/02/linkedin1-150x150.jpg" alt="" title="linkedin1" width="150" height="150" style="border:1px solid #eee;" class="alignleft size-thumbnail wp-image-506" /></a>LinkedIn (<a href="http://www.linkedin.com">www.linkedin.com</a>) is one of the famous professional social network in the world. They connect many professionals around the world through their network. One of nice feature on LinkedIn is you can update status message. They called it &#8216;What are you working on?&#8217;. Here is simple PHP code that can update status message on your LinkedIn account. This code is using PHP libcurl.<span id="more-501"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// script name: update_linkedin_status.php</span>
  <span style="color: #666666; font-style: italic;">// coder: Sony AK Knowledge Center - www.sony-ak.com</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// set linkedin credentials</span>
  <span style="color: #000088;">$linkedInUsername</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_linkedin_email_account&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$linkedInPassword</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_linkedin_password&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// login to linkedin</span>
  <span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;https://m.linkedin.com/session&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;login=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$linkedInUsername</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;password=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$linkedInPassword</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;commit=Sign+In&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_ENCODING<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_COOKIEJAR<span style="color: #339933;">,</span> <span style="color: #990000;">getcwd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/cookies_linkedin.cookie'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$curlData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// update your linkedin status</span>
  <span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;http://m.linkedin.com/network_updates&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;status=at office now...&amp;commit=Save&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_ENCODING<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_COOKIEFILE<span style="color: #339933;">,</span> <span style="color: #990000;">getcwd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/cookies_linkedin.cookie'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_COOKIEJAR<span style="color: #339933;">,</span> <span style="color: #990000;">getcwd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/cookies_linkedin.cookie'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$curlData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Done!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Save it as update_linkedin_status.php. The logic is simple, actually we only simulate login to the LinkedIn mobile version and change the status from there. Below is the sample result on the LinkedIn profile.</p>
<div id="attachment_502" class="wp-caption aligncenter" style="width: 594px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/02/linkedin_status.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/02/linkedin_status.jpg" alt="Sample of updated LinkedIn status message" title="linkedin_status" width="584" height="182" class="size-full wp-image-502" /></a><p class="wp-caption-text">Sample of updated LinkedIn status message</p></div>
<p>If you have any difficulty, please send comment below or drop us e-mail to info@sony-ak.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sony-ak.com/2010/02/update-status-on-linkedin-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a Simple &#8216;Forget Password&#8217; Feature using PHP</title>
		<link>http://www.sony-ak.com/2010/02/create-a-simple-forget-password-feature-using-php/</link>
		<comments>http://www.sony-ak.com/2010/02/create-a-simple-forget-password-feature-using-php/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 17:53:34 +0000</pubDate>
		<dc:creator>Sony AK</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[forget]]></category>
		<category><![CDATA[forget password]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[lost]]></category>
		<category><![CDATA[lost password]]></category>
		<category><![CDATA[lupa]]></category>
		<category><![CDATA[lupa password]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.sony-ak.com/?p=474</guid>
		<description><![CDATA[One of very common feature on a community or social network website is &#8216;forget password&#8217; feature. What the hell is that? Well, it&#8217;s seems this feature is not important, but actually it will be useful if the member of the site was forgot their password. How to create a simple but quite good &#8216;forget password&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sony-ak.com/wp-content/uploads/2010/02/forget_img.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/02/forget_img-150x150.jpg" alt="" style="border:1px solid #eee;" title="forget_img" width="150" height="150" class="alignleft size-thumbnail wp-image-490" /></a>One of very common feature on a community or social network website is &#8216;forget password&#8217; feature. What the hell is that? Well, it&#8217;s seems this feature is not important, but actually it will be useful if the member of the site was forgot their password. How to create a simple but quite good &#8216;forget password&#8217; feature? As usual, we will need a scenario to reproduce our problem. But before we talk about the scenario, we will cover about our &#8216;forget password&#8217; mechanism first.<span id="more-474"></span></p>
<p>1. Suppose someone has forgot the password on your site<br />
2. We will provide her with forget password page<br />
3. We ask her to input her username on that page<br />
4. Your software will search the username on the database, if username found then send e-mail that associated with that username that contains the special URL to reset the password.<br />
5. It&#8217;s clear that on point (4) above, we will provide the user to RESET the password, not to RETRIEVE the forgotten password.</p>
<p>Now we will create the user table that store the username and password.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> tbl_users <span style="color: #66cc66;">&#40;</span>
  id int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  username varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  password varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  forget_pass_key varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  email varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM  <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>latin1 ;</pre></td></tr></table></div>

<p>Now we will add some data to that table.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">INSERT INTO tbl_users <span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> username<span style="color: #339933;">,</span> password<span style="color: #339933;">,</span> forget_pass_key<span style="color: #339933;">,</span> email<span style="color: #009900;">&#41;</span> VALUES
<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sonyak'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'c0b137fe2d792459f26ff763cce44574a5b5ab03'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sony@sony-ak.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'esaivani'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'c0b137fe2d792459f26ff763cce44574a5b5ab03'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'esa@sony-ak.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ingrid'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'c0b137fe2d792459f26ff763cce44574a5b5ab03'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ingrid@anu.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You can see the above SQL statement, the password field is using SHA1 hash string. The actual password string is &#8216;welcome&#8217;.</p>
<p>Now we will create the forget password page.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Forget Password&lt;/title&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&lt;p&gt;Forget Password sample page. On this page, the user will input their username.&lt;br&gt;
  Copyright &amp;copy; Sony AK Knowledge Center - www.sony-ak.com&lt;/p&gt;
&lt;form method=&quot;post&quot; action=&quot;p_forget_password.php&quot;&gt;
Username:&lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot;&gt;&lt;input name=&quot;submit&quot; type=&quot;submit&quot; id=&quot;submit&quot; value=&quot;Forget Password&quot;&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<div id="attachment_485" class="wp-caption aligncenter" style="width: 513px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/02/forget_password.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/02/forget_password.jpg" alt="Forget password page" title="forget_password" width="503" height="217" class="size-full wp-image-485" /></a><p class="wp-caption-text">Forget password page</p></div>
<p>Save it as forget_password.php. On the form action above we will do the &#8216;forget password&#8217; process on p_forget_password.php script. Now here is the p_forget_password.php code.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// script name: p_forget_password.php</span>
  <span style="color: #666666; font-style: italic;">// coder: Sony AK Knowledge Center - www.sony-ak.com</span>
&nbsp;
  <span style="color: #000088;">$dbConn</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;your_db_username&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;your_db_password&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Connection to database failed, perhaps the service is down !!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;your_database_name&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Database name not available !!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// random string generator, i took the code from</span>
  <span style="color: #666666; font-style: italic;">// http://www.lost-in-code.com/programming/php-code/php-random-string-with-numbers-and-letters/</span>
  <span style="color: #000000; font-weight: bold;">function</span>  genRandomString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$characters</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0123456789abcdefghijklmnopqrstuvwxyz&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$p</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$length</span><span style="color: #339933;">;</span> <span style="color: #000088;">$p</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$characters</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">mt_rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$characters</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000088;">$sqlString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM tbl_users WHERE username = '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$resultSet</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sqlString</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbConn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resultSet</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$forgetPasswordKey</span> <span style="color: #339933;">=</span> genRandomString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resultSet</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// update the forget_pass_key field on the tbl_users</span>
    <span style="color: #000088;">$sqlString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UPDATE tbl_users SET forget_pass_key = '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$forgetPasswordKey</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;' WHERE username = '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sqlString</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbConn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// send email to us</span>
    <span style="color: #000088;">$to</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$email</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Your password reset request!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Dear &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Here is the URL to reset your password:<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;http://your-server-domain.com/reset_password.php?u=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;fpk=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$forgetPasswordKey</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Thank you.<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Sony AK Knowledge Center&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;From: Password Reset &lt;noreply@sony-ak.com&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">.</span>
               <span style="color: #0000ff;">&quot;Reply-To: noreply@sony-ak.com&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">.</span>
               <span style="color: #0000ff;">&quot;X-Mailer: PHP/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">phpversion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;We sent you e-mail to reset your password!&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;We can't found the username!&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The script above will send e-mail to e-mail address that associated with requested username. The e-mail body will contains the special URL that points to &#8216;reset_password.php&#8217; page.</p>
<div id="attachment_486" class="wp-caption aligncenter" style="width: 562px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/02/forget_password_response_email.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/02/forget_password_response_email.jpg" alt="Sample of e-mail message that request for password reset" title="forget_password_response_email" width="552" height="304" class="size-full wp-image-486" /></a><p class="wp-caption-text">Sample of e-mail message that request for password reset</p></div>
<p>You can adjust some settings on above script, for example the database settings and the URL in the body of your e-mail.</p>
<p>Here is the &#8216;reset_password.php&#8217; script.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// script name: reset_password.php</span>
  <span style="color: #666666; font-style: italic;">// coder: Sony AK Knowledge Center - www.sony-ak.com</span>
&nbsp;
  <span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$dbConn</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;your_db_username&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;your_db_password&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Connection to database failed, perhaps the service is down !!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;your_database_name&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Database name not available !!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'u'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$forgetPasswordKey</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fpk'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$sqlString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM tbl_users WHERE username = '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;' AND forget_pass_key = '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$forgetPasswordKey</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$resultSet</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sqlString</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbConn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resultSet</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$username</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'forget_password_key'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$forgetPasswordKey</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// the username not match with the forget password key</span>
    <span style="color: #666666; font-style: italic;">// perhaps someone wants to spam the reset password service</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Not valid URL!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'forget_password_key'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">session_destroy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Reset Password&lt;/title&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&lt;p&gt;Reset Password sample page. You must input your new password here.&lt;br /&gt;
Copyright &amp;copy; Sony AK Knowledge Center - www.sony-ak.com&lt;/p&gt;
&lt;form method=&quot;post&quot; action=&quot;p_reset_password.php&quot;&gt;
Username: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$username</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;br/&gt;
New password:
&lt;input type=&quot;password&quot; name=&quot;password&quot; id=&quot;password&quot; /&gt;
&lt;br/&gt;
Retype New password:
&lt;input type=&quot;password&quot; name=&quot;retype_password&quot; id=&quot;retype_password&quot; /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; id=&quot;submit&quot; value=&quot;Submit&quot;/&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<div id="attachment_487" class="wp-caption aligncenter" style="width: 480px"><a href="http://www.sony-ak.com/wp-content/uploads/2010/02/reset_password.jpg"><img src="http://www.sony-ak.com/wp-content/uploads/2010/02/reset_password.jpg" alt="Reset password page to input the new password from user" title="reset_password" width="470" height="228" class="size-full wp-image-487" /></a><p class="wp-caption-text">Reset password page to input the new password from user</p></div>
<p>On the &#8216;reset_password.php&#8217; above, we will ask the user to input the new password and will be processed by &#8216;p_reset_password.php&#8217; script. Here is the code for &#8216;p_reset_password.php&#8217; script.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// script name: p_reset_password.php</span>
  <span style="color: #666666; font-style: italic;">// coder: Sony AK Knowledge Center - www.sony-ak.com</span>
&nbsp;
  <span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Not valid URL!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'forget_password_key'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">session_destroy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000088;">$dbConn</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;your_db_username&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;your_db_password&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Connection to database failed, perhaps the service is down !!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;your_database_name&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Database name not available !!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$retypePassword</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'retype_password'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$forgetPasswordKey</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'forget_password_key'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// validate the password match</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$retypePassword</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Password not match!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'forget_password_key'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">session_destroy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// validate blank password</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$retypePassword</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Password cannot blank!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'forget_password_key'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">session_destroy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// update password with sha1 hash</span>
  <span style="color: #000088;">$sqlString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UPDATE tbl_users SET password = sha1('&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$password</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;') WHERE username = '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;' AND forget_pass_key = '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$forgetPasswordKey</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sqlString</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbConn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// update forget_pass_key field to NULL again</span>
  <span style="color: #000088;">$sqlString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UPDATE tbl_users SET forget_pass_key = NULL WHERE username = '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;' AND forget_pass_key = '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$forgetPasswordKey</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sqlString</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbConn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Your password has been reset!&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'forget_password_key'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">session_destroy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You can see on script above, we do some checking before we update the password. If everything goess right, then the password will be successfuly updated with the new one. You still can improve and adjust the code above or even improve the mechanism with your own preference. There are many different implementation of &#8216;forget password&#8217; or &#8216;lost password&#8217; feature we already saw on many web sites.</p>
<p>If you have any difficulty, please send comment below or drop us e-mail to info@sony-ak.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sony-ak.com/2010/02/create-a-simple-forget-password-feature-using-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Code -->
