<?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>HTTPguru</title>
	<atom:link href="http://httpguru.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://httpguru.com</link>
	<description>A world for usability</description>
	<lastBuildDate>Thu, 11 Mar 2010 14:02:59 +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>Introduction to Mate Framework</title>
		<link>http://httpguru.com/featured/introduction-to-mate-framework/</link>
		<comments>http://httpguru.com/featured/introduction-to-mate-framework/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 13:42:42 +0000</pubDate>
		<dc:creator>Vinothbabu</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Featured]]></category>

		<guid isPermaLink="false">http://httpguru.com/?p=189</guid>
		<description><![CDATA[Mate is one of the best framework i have ever played with. It is completely unobtrusive.  My application code has no dependencies on the framework, it is highly decoupled, reusable and testable. Mate framework is developed by AsFusion.
Let me point out why i have switched over to Mate over Cairngorm
1. You can dispatch an event from [...]]]></description>
			<content:encoded><![CDATA[<p>Mate is one of the best framework i have ever played with. It is completely unobtrusive.  My application code has no dependencies on the framework, it is highly decoupled, reusable and testable. <strong>Mate framework is developed by AsFusion.</strong><span id="more-189"></span></p>
<p>Let me point out why i have switched over to Mate over <strong>Cairngorm</strong></p>
<p>1. You can dispatch an event from anywhere in the view hierarchy and have it bubble up to the framework automatically, instead of having to have a direct line, like Cairngorms CairngormEventDispatcher or PureMVC&#8217;s notification system.</p>
<p>2. Mate is extremely light and readable, being a Flex framework which is built on the Event Map idea. This is a collation of handlers that can respond to all the incoming events and complete several actions that are appropriate for the target.</p>
<p>3. By using the Mate framework, you will need no more the Singletons. I have seen a quite a few people using Singleton pattern, when it is actually not needed in the application. Now Mate completely removes it, which actually makes development further easier.</p>
<p>4. Mate also uses a form of dependency injection (leveraging bindings) that makes it possible to connect your models to your views without either one knowing about the other. <strong>This is probably the most powerful feature of the framework.</strong></p>
<p>5. The RIA development is most certainly more interesting and flexible with Mate.</p>
<p>My View on <strong>Cairngorm</strong></p>
<p><strong>Cairngorm is a bundle of anti-patterns that lead to applications that are tightly coupled to global variables.</strong></p>
<p style="text-align: center;">Let me explain you the flow on how Mate really goes, its so easy and interesting like <strong>RajiniKanth </strong>sir Movie.<img class="aligncenter" src="http://mate.asfusion.com/assets/content/diagrams/two_way_view_injection.png" alt="" width="594" height="629" /></p>
<p>This tutorial explains how to get started with Mate. As an example, we&#8217;ll be sending two numbers to our manager class to add , receives the total value and stores it in the model for the view to show.</p>
<p>All Mate projects must have:</p>
<ol>
<li>One or more events (custom or built-in)</li>
<li>One or more Event Maps</li>
</ol>
<p><strong>Let us go step by step</strong></p>
<p>Create a new Flex project named AdditionExample. In the libs folder it creates, place the compiled framework SWC (Mate.swc). This will let you use all Mate classes and tags.Create a folder structure as displayed in the image below, i will explain you how the entire flow goes.</p>
<p style="text-align: center;"><a href="http://httpguru.com/wp-content/uploads/2009/12/structureimage.jpg"><img class="size-medium wp-image-191 aligncenter" title="structureimage" src="http://httpguru.com/wp-content/uploads/2009/12/structureimage-279x300.jpg" alt="" width="279" height="300" /></a></p>
<h2>The custom event</h2>
<p>Every Mate project is driven by events. In our example, when user enters two values and clicks on the Add button, we&#8217;ll create a new event containing that information that will be sent to the manager class to perform the addiiton. For this purpose, we create a custom event to indicate that the user wants to submit the data and retrieve the total.</p>
<p>Our event will be very simple and it will contain two property: the <strong>number1 </strong>and <strong>number2</strong>.</p>
<blockquote><p>package com.vinoth.example.events<br />
{<br />
import flash.events.Event;</p>
<p>public class AdditionEvent extends Event<br />
{<br />
public static const GET: String = &#8220;getQuoteEvent&#8221;;</p>
<p>public var number1 : Number;<br />
public var number2 : Number;</p>
<p>public function AdditionEvent(type:String, bubbles:Boolean=true,        cancelable:Boolean=false)<br />
{<br />
super(type, bubbles, cancelable);<br />
}</p>
<p>}<br />
}</p></blockquote>
<p>The code above assumes this event is contained within the package: <strong>com.vinoth.example.events</strong></p>
<p>The event also contains a constant that we will use to specify the event type. One event can specify more than one event type. We also make this event bubble up by default (the second argument of the constructor). Otherwise, we will need to remember to specify it when we instantiate it.</p>
<h2>The View</h2>
<p style="text-align: center;"><a href="http://httpguru.com/wp-content/uploads/2009/12/ui.jpg"><img class="size-medium wp-image-192 aligncenter" title="ui" src="http://httpguru.com/wp-content/uploads/2009/12/ui-300x224.jpg" alt="" width="300" height="224" /></a></p>
<p>The user interface will only need two text input and a button.</p>
<h2>Dispatching the Custom Event</h2>
<p>When the user clicks the Add button, we&#8217;ll create the AdditionEvent and dispatch it:</p>
<blockquote><p>package com.vinoth.example.events<br />
{<br />
import flash.events.Event;</p>
<p>public class AdditionEvent extends Event<br />
{<br />
public static const GET: String = &#8220;getQuoteEvent&#8221;;</p>
<p>public var number1 : Number;<br />
public var number2 : Number;</p>
<p>public function AdditionEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=false)<br />
{<br />
super(type, bubbles, cancelable);<br />
}</p>
<p>}<br />
}</p></blockquote>
<h2>The Event Map</h2>
<p>EventMap is a place where the we place all the handlers for the events which the application creates. There are be n number of event map. Now let me put down before you on how to create an event map.</p>
<p>We need to create a MXML file with name&#8221;MainEventMap&#8221;. This MXML component must extend from EventMap.</p>
<blockquote><p><code>&lt;?xml version=<span class="cc_value">"1.0"</span> encoding=<span class="cc_value">"utf-8"</span>?&gt;<br />
<span class="cc_normaltag">&lt;EventMap<br />
xmlns:mx=<span class="cc_value">"http://www.adobe.com/2006/mxml"</span><br />
xmlns=<span class="cc_value">"http://mate.asfusion.com/"</span>&gt;</span></code></p>
<p><span class="cc_normaltag">&lt;/EventMap&gt;</span></p></blockquote>
<p>This is how your blank event map file will look like. We&#8217;ll add the event map to our main Application file.</p>
<blockquote><p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<br />
&lt;mx:Application xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221; layout=&#8221;absolute&#8221;<br />
xmlns:maps=&#8221;com.vinoth.example.maps.*&#8221;<br />
&gt;</p>
<p>&lt;!&#8211; Styles______________________________________________________ &#8211;&gt;</p>
<p>&lt;mx:Style source=&#8221;/assets/styles/main.css&#8221;/&gt;</p>
<p>&lt;!&#8211; Event Maps __________________________________________________ &#8211;&gt;</p>
<p>&lt;maps:MainEventMap /&gt;</p>
<p>&lt;/mx:Application&gt;</p></blockquote>
<p>Now here a question might rise, how could i know whether my event map is receiving the events being dispatched.</p>
<blockquote><p><code><span class="cc_normaltag">&lt;Debugger level=<span class="cc_value">"{Debugger.ALL}"</span> /&gt;</span></code></p></blockquote>
<p>This Tag does come handy and helps you in debugging whether you are going on the right way. Adding this to the event map looks like this.</p>
<blockquote><p><code>&lt;?xml version=<span class="cc_value">"1.0"</span> encoding=<span class="cc_value">"utf-8"</span>?&gt;<br />
<span class="cc_normaltag">&lt;EventMap<br />
xmlns:mx=<span class="cc_value">"http://www.adobe.com/2006/mxml"</span><br />
xmlns=<span class="cc_value">"http://mate.asfusion.com/"</span>&gt;</span></code></p>
<p><code><span class="cc_normaltag">&lt;Debugger level=<span class="cc_value">"{Debugger.ALL}"</span> /&gt;</span></code><br />
<code><br />
<span class="cc_normaltag">&lt;/EventMap&gt;</span></code></p></blockquote>
<h2>Listening for AdditionEvent.GET</h2>
<p>In our event map, we will listen for the addition event so that we can send the request to the manager class. We&#8217;ll add EventHandlers tag which will specify what event type we are listening too.</p>
<blockquote><p><code><span class="cc_normaltag">&lt;EventHandlers type=<span class="cc_value">"{AdditionEvent.GET}"</span> debug=<span class="cc_value">"true"</span>&gt;</span></code></p>
<p><span class="cc_normaltag">&lt;/EventHandlers&gt;</span></p></blockquote>
<p>At the top of the event map we&#8217;ll need to import the event class.</p>
<blockquote><p><code><span class="cc_normaltag">&lt;mx:Script&gt;</span><br />
&lt;![CDATA[<br />
import com.vinoth.example.events.AdditionEvent<br />
]]&gt;<br />
<span class="cc_normaltag">&lt;/mx:Script&gt;</span></code></p></blockquote>
<p>Inside this EventHandlers block, we&#8217;ll place the actions we want to perform when the event is dispatched. In our example we will call the method addValues in the AddManager Class.</p>
<blockquote><p>&lt;EventHandlers type=&#8221;{AdditionEvent.GET}&#8221; debug=&#8221;true&#8221;&gt;<br />
&lt;MethodInvoker generator=&#8221;{AddManager}&#8221;<br />
method=&#8221;addValues&#8221; arguments=&#8221;{[event.number1,event.number2]}&#8221;/&gt;<br />
&lt;/EventHandlers&gt;</p></blockquote>
<p>We are calling the method addValues on that service and sending the values coming from the event  as an argument.</p>
<h2>Creating our Business, the AddManager</h2>
<blockquote><p>package com.vinoth.example.business<br />
{<br />
import mx.controls.Alert;</p>
<p>public class AddManager<br />
{</p>
<p>[Bindable]<br />
public var totalValue:Number;</p>
<p>// &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
public function addValues(number1:Number,number2:Number):void {<br />
totalValue = number1+number2;</p>
<p>}</p>
<p>}<br />
}</p></blockquote>
<p>In this Class we are getting the two numbers as arguments from the event class which dispatches and then we are doing our calculation. Once the value is calculated, we will inject the result in our view.</p>
<blockquote><p>&lt;Injectors target=&#8221;{YourViewPanel}&#8221;&gt;<br />
&lt;PropertyInjector targetKey=&#8221;value&#8221; source=&#8221;{AddManager}&#8221; sourceKey=&#8221;totalValue&#8221; /&gt;<br />
&lt;/Injectors&gt;</p></blockquote>
<p>This makes life simple, here we get the final result. You can have a <strong>look </strong>at the application and view source is <strong>enabled</strong>.</p>
<p><a href="http://www.httpguru.com/Flex-Examples/mateExample/mateExample.html" target="_blank">Application</a></p>
]]></content:encoded>
			<wfw:commentRss>http://httpguru.com/featured/introduction-to-mate-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML HTTP Request Object &#8211; AJAX</title>
		<link>http://httpguru.com/featured/xml-http-request-object-ajax/</link>
		<comments>http://httpguru.com/featured/xml-http-request-object-ajax/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 07:46:27 +0000</pubDate>
		<dc:creator>Vinothbabu</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[JavaScript & Ajax]]></category>

		<guid isPermaLink="false">http://httpguru.com/?p=176</guid>
		<description><![CDATA[I thought of inditing a very basic example of AJAX which will make the new comers ease their mind. In RajiniKanth Style, I would generally say AJAX as a technique rather than being called as Technology. Its nothing but how you can use JavaScript to pull data from the server using XML HTTP Request object [...]]]></description>
			<content:encoded><![CDATA[<p>I thought of inditing a very basic example of AJAX which will make the new comers ease their mind. In <strong>RajiniKanth </strong>Style, I would generally say AJAX as a technique rather than being called as Technology. Its nothing but how you can use JavaScript to pull data from the server using XML HTTP Request object and then insert the data using DOM. <span id="more-176"></span><strong>XML HTTP Request Object</strong></p>
<p>The XML HTTP Request object is used to make HTTP requests. I realised the power of the XML HTTP Request when gmail.com was lanuched. Its actually a dream come true. Why is this much spoken?</p>
<p>1. You can update a page without reloading the entire page.<br />
2. You can send data to server in background.<br />
3. You can request and receive data from server after the page has loaded.</p>
<p>Let us go in depth which will give you a broader idea.</p>
<p><strong>Creating the Object</strong></p>
<p>Its a sort of pain for developers, but you need to get it going as browsers do vary their style in creating the object. In <strong>Internet Explorer</strong>, We create the object using new ActiveXObject(&#8220;Msxml2.XMLHTTP&#8221;) or new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;) depending upon the version of MSXML installed.</p>
<p>In <strong>Mozilla</strong> and <strong>Safari </strong>you use new XMLHttpRequest() <strong>IceBrowser </strong>uses yet another method the window.createRequest() method.</p>
<blockquote><p>var httpReqObject=false;</p>
<p>try {<br />
httpReqObject= new ActiveXObject(&#8220;Msxml2.XMLHTTP&#8221;);<br />
} catch (e) {<br />
try {<br />
httpReqObject= new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;);<br />
} catch (E) {<br />
httpReqObject= false;<br />
}<br />
}</p>
<p>if (!httpReqObject&amp;&amp; typeof XMLHttpRequest!=&#8217;undefined&#8217;) {<br />
try {<br />
httpReqObject= new XMLHttpRequest();<br />
} catch (e) {<br />
httpReqObject=false;<br />
}<br />
}</p>
<p>if (!httpReqObject&amp;&amp; window.createRequest) {<br />
try {<br />
httpReqObject= window.createRequest();<br />
} catch (e) {<br />
httpReqObject=false;<br />
}<br />
}</p>
</blockquote>
<p>We initially set the xmlhttp variable to false, If the browser Object is not being created, then it throws the appropriate error message while setting the variable to false. The Above script does for all the browsers.</p>
<p><strong>Now let us see how to make a Request?</strong></p>
<p>Now that you have the HTTP request object in hand, let us tell the object on what request which url you want to. A function should be called as when the request is made, and what information you want to send along in the body of the request.</p>
<blockquote><p>// The Type of request you send and the corresponding url.<br />
httpReqObject.open(&#8220;GET&#8221;, &#8220;test.txt&#8221;,true);</p>
<p>// Here we call the function and check whether the readyState is 4, then shoot the alert message.<br />
httpReqObject.onreadystatechange=function() {<br />
if (httpReqObject.readyState==4) {<br />
alert(httpReqObject.responseText)<br />
}<br />
}<br />
httpReqObject.send(null)</p>
</blockquote>
<p>Now at the same time, i can use the status to check whether the URL exists or not.</p>
<blockquote><p>if (xmlhttp.status==200) alert(&#8220;URL does Exists!&#8221;)</p>
</blockquote>
<p>Let us jump into the well slightly in depth.  <strong>Common XML HTTP Request Object Methods.</strong></p>
<p>httpReqObject.<strong>abort</strong>() will stop the current request.</p>
<p><strong>getAllResponseHeaders</strong>() will return you the complete set of headers (labels and values) as a string.<br />
When you go for a HEAD request, the server will return the headers of a resource that means you can find out the Content-Type or Last-Modified of a document without downloading.</p>
<blockquote><p>HTTP/1.1 200 OK<br />
Server: Microsoft-IIS/4.0<br />
Cache-Control: max-age=172800<br />
Expires: Sat, 06 Apr 2002 11:34:01 GMT<br />
Date: Thu, 04 Apr 2002 11:34:01 GMT<br />
Content-Type: text/html<br />
Accept-Ranges: bytes<br />
Last-Modified: Thu, 14 Mar 2002 12:06:30 GMT<br />
ETag: &#8220;0a7ccac50cbc11:1aad&#8221;<br />
Content-Length: 52282</p>
</blockquote>
<p><strong>getResponseHeader</strong>(&#8220;headerLabel&#8221;) will return you the string value of a single header label. What is this headerLabel?</p>
<blockquote><p>httpReqObject.getResponseHeader(&#8220;Last-Modified&#8221;)) [ This will throw you the following below ]<br />
Last-Modified: Thu, 14 Mar 2002 12:06:30 GMT</p>
</blockquote>
<p><strong>open</strong>(&#8220;method&#8221;, &#8220;URL&#8221;[, asyncFlag[, "userName"[, "password"]]])</p>
<p>The Method name is GET , following with a url and boolean which indicates whether or not the request will be asynchronous. Normally the open method does accepst five parameters and there are different type of Requests. The fourth and fifth parameters are the URL user and password, respectively.</p>
<blockquote><p># GET<br />
# POST<br />
# HEAD<br />
# PUT<br />
# DELETE<br />
# OPTIONS</p>
</blockquote>
<p>httpReqObject.<strong>send</strong>(content)</p>
<p>This method accepts a single parameter containing the content to be sent with the request.</p>
<blockquote><p>function mySubmit(id) {<br />
var url    = &#8220;submitForm.php&#8221;;<br />
var params = &#8220;id=&#8221; + id;</p>
<p>httpReqObject.open(&#8220;POST&#8221;, url, true);</p>
<p>//Send the header information along with the request<br />
httpReqObject.setRequestHeader(&#8220;Content-type&#8221;, &#8220;application/x-www-form-urlencoded&#8221;);<br />
httpReqObject.setRequestHeader(&#8220;Content-length&#8221;, params.length);<br />
httpReqObject.setRequestHeader(&#8220;Connection&#8221;, &#8220;close&#8221;);</p>
<p>httpReqObject.onreadystatechange = onPostSubmit;<br />
httpReqObject.send(params);</p>
<p>}</p>
</blockquote>
<p>Here i am sending the params in the send method along with the headers. It is essential that the data returned from the server be sent with a Content-Type set to text/xml. Content that is sent as text/plain or text/html is accepted by the instance of the request object however it will only be available for use via the responseText property.</p>
<p><strong>setRequestHeader</strong>(&#8220;label&#8221;, &#8220;value&#8221;)</p>
<p>The setRequestHeader method can be invoked to send HTTP headers with the request. The first parameter would be a strign name and the second parameter with a strign value.</p>
<blockquote><p>httpReqObject.setRequestHeader(&#8220;Content-type&#8221;, &#8220;application/x-www-form-urlencoded&#8221;);</p>
</blockquote>
<p><strong>Common XMLHttpRequest Object Properties</strong></p>
<p><strong>readyState</strong></p>
<p>Object status integer:<br />
0 = uninitialized<br />
1 = loading<br />
2 = loaded<br />
3 = interactive<br />
4 = complete</p>
<p><strong>onreadystatechange</strong></p>
<p>When the open method of httpReqObject object is invoked with a third parameter set to true, the on readystatechange event listner will be called for the following actions that change the readyState property of the object.</p>
<p>1. When the open method has been invoked successfully, the readyState property of the object should be assigned a value 1.<br />
2. Once the send method has been invoked and corresponding response headers has been recieved, the readyState property should beassigned to<br />
3. Once the HTTP response content starts loading, the readyState property should beassigned a value of 3.<br />
4. Finally when the content has finished loading, the readyState property should be assigned a value of 4.</p>
<p><strong>responseText</strong></p>
<p>String version of data returned from server process</p>
<p><strong>responseXML</strong></p>
<p>DOM-compatible document object of data returned from server process</p>
<p><strong>status</strong></p>
<p>Numeric code returned by server, such as 404 for &#8220;Not Found&#8221; or 200 for &#8220;OK&#8221;</p>
<p><strong>statusText</strong></p>
<p>String message accompanying the status code</p>
<p>With this, i think i have covered to some extent of the XML HTTP Request Object. AJAX is a wonderful thing if you go on playing with it. I will get back a finishing style like RajniKanth with an example showing the power of AJAX.</p>
]]></content:encoded>
			<wfw:commentRss>http://httpguru.com/featured/xml-http-request-object-ajax/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Loading a xml file using custom class</title>
		<link>http://httpguru.com/featured/loading-a-xml-file-using-custom-class/</link>
		<comments>http://httpguru.com/featured/loading-a-xml-file-using-custom-class/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 09:31:51 +0000</pubDate>
		<dc:creator>Vinothbabu</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Featured]]></category>

		<guid isPermaLink="false">http://httpguru.com/?p=171</guid>
		<description><![CDATA[How nice it would be if we have a custom class which can load any xml or data file without much headache? Today while coding my application, i thought of bounding this in as it might be useful for the rest of developers to just call the file alone.
package utils {
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.system.Security;
public [...]]]></description>
			<content:encoded><![CDATA[<p>How nice it would be if we have a custom class which can load any xml or data file without much headache? Today while coding my application, i thought of bounding this in as it might be useful for the rest of developers to just call the file alone.<span id="more-171"></span></p>
<blockquote><p>package utils {</p>
<p>import flash.events.Event;<br />
import flash.net.URLLoader;<br />
import flash.net.URLRequest;<br />
import flash.system.Security;<br />
public class UrlXloader<br />
{</p>
<p>private static var _instance : UrlXloader = null;</p>
<p>public static function get instance() : UrlXloader {<br />
if(_instance == null){<br />
_instance = new UrlXloader();<br />
Security.allowDomain(&#8216;*&#8217;);</p>
<p>}<br />
return _instance;<br />
}</p>
<p>public function loadtheFile(fileRef : String, vinothLoad : Function):void{<br />
var request:URLRequest=new URLRequest(fileRef);<br />
var loader:URLLoader=new URLLoader();<br />
try<br />
{<br />
loader.load(request);<br />
loader.addEventListener(Event.COMPLETE, vinothLoad);<br />
}<br />
catch (error:ArgumentError)<br />
{<br />
throw new Error(&#8220;An ArgumentError has occurred.&#8221;);<br />
}<br />
catch (error:SecurityError)<br />
{<br />
throw new Error(&#8220;A SecurityError has occurred.&#8221; + error.message);<br />
}<br />
}<br />
}<br />
}</p></blockquote>
<p>To start with, i am possibly making sure only single instance of a class is created by using a static initializer and checking it inside the function. [ <strong>Security.allowDomain('*'); ] </strong>The wildcard (*) value permits cross-scripting operations where the accessing file is any file at all,    loaded from anywhere. At the next line you return the instance.</p>
<p>The rest of lines below are the usual things on how to perform a request and load the request using URLLoader class.</p>
<p><strong>How to use the class file in your application.</strong></p>
<blockquote><p>UrlXloader.instance.loadtheFile(&#8220;filename.xml&#8221;, <strong>handleVinoth</strong>);</p>
<p>private function handleVinoth(event:Event):void<br />
{<br />
var dataXML:XML = XML(event.target.data);<br />
}</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://httpguru.com/featured/loading-a-xml-file-using-custom-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Oracle to buy Sun for $9.50 a share</title>
		<link>http://httpguru.com/tech-sambar/oracle-to-buy-sun-for-950-a-share/</link>
		<comments>http://httpguru.com/tech-sambar/oracle-to-buy-sun-for-950-a-share/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 10:40:59 +0000</pubDate>
		<dc:creator>Vinothbabu</dc:creator>
				<category><![CDATA[Tech Sambar]]></category>

		<guid isPermaLink="false">http://httpguru.com/?p=168</guid>
		<description><![CDATA[Business software maker Oracle Corp. said Monday it has entered into a definitive agreement to buy server builder Sun Microsystems in a deal worth $7.4 billion.Oracle said it will buy Sun common stock for $9.50 per share in cash, a 42% premium from Friday&#8217;s closing price of $6.69.
Personally what i feel is it would be [...]]]></description>
			<content:encoded><![CDATA[<p>Business software maker Oracle Corp. said Monday it has entered into a definitive agreement to buy server builder Sun Microsystems in a deal worth $7.4 billion.Oracle said it will buy Sun common stock for $9.50 per share in cash, a 42% premium from Friday&#8217;s closing price of $6.69.<span id="more-168"></span></p>
<p>Personally what i feel is it would be majuscule for the JAVA community, but i am yet to know about the fate of my favourate product <strong>MySQL. </strong>It would be a wise move from ORACLE community if they build a bridge for MySQL and ORACLE and attract the exisiting MySQL users to ORACLE.</p>
<p><strong>Three years back, when ORACLE tried to buy MySQL.</strong></p>
<p>MySQL Chief Executive Marten Mickos confirmed the acquisition attempt in an interview at the Open Source Business Conference here but wouldn&#8217;t provide details such as when the approach was made or how much money Oracle offered.</p>
<p>He did, however, say why he turned down Oracle&#8217;s offer: the desire to keep his company&#8217;s independence. &#8220;We will be part of a larger company, but it will be called MySQL,&#8221; Mickos said.</p>
<p><strong>My Final Conclusion:</strong></p>
<p>Its a known epic to all, SUN own MySQL and now the tale has changed with ORACLE entering the scene buying the SUN. Its a good time to say farwell to your beloved old amigo MySQL. It was nice knowing you so long my dear amigo MySQL.</p>
]]></content:encoded>
			<wfw:commentRss>http://httpguru.com/tech-sambar/oracle-to-buy-sun-for-950-a-share/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sanitizing your database Inputs</title>
		<link>http://httpguru.com/featured/sanitizing-your-database-inputs/</link>
		<comments>http://httpguru.com/featured/sanitizing-your-database-inputs/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 11:53:25 +0000</pubDate>
		<dc:creator>Vinothbabu</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP & MySQL]]></category>

		<guid isPermaLink="false">http://httpguru.com/?p=163</guid>
		<description><![CDATA[Today i was looking at the code of my fellow team members and was shocked, none of them have santized data before making it to database. I thought of putting this article before you so that it would be helpful for those who are not aware of such practice. Santizing means you are inspecting your [...]]]></description>
			<content:encoded><![CDATA[<p>Today i was looking at the code of my fellow team members and was shocked, none of them have santized data before making it to database. I thought of putting this article before you so that it would be helpful for those who are not aware of such practice. <span id="more-163"></span>Santizing means you are inspecting your data that it does not contain any malicious code, such as javascript. Also is to make sure when you are data is inserting or getting updated, it doesn&#8217;t break the SQL and do some nasty things. Pref i would be say&#8230; lets be aware of SQL injection attack.</p>
<p>When your form is submitted, then it gets stored in $_GET or $_POST global array, with this information in the hand we can perform a lot of things.</p>
<p><strong>Strip_tags()</strong></p>
<blockquote><p>&lt;?php<br />
$input = &#8216;&lt;p&gt;My name is Vinothbabu.&lt;/p&gt;&lt;!&#8211; Comment &#8211;&gt; &lt;a href=&#8221;http://www.vinothbabu.com&#8221;&gt;My Blog&lt;/a&gt;&#8217;;<br />
echo strip_tags($input);<br />
echo strip_tags($input, &#8216;&lt;p&gt;&lt;a&gt;&#8217;);<br />
?&gt;</p></blockquote>
<p>The output of the following code will be &#8230;</p>
<p>My name is Vinothbabu. My Blog<br />
&lt;p&gt;My name is Vinothbabu&lt;/p&gt; &lt;a href=&#8221;http://www.vinothbabu.com&#8221;&gt;My Blog&lt;/a&gt;</p>
<p>The second line, you have additional parameter called allowable_tags, which will allow those tags specified.</p>
<p><strong>Some times back when i was coding for my application for a client,</strong> i came across this situation where i have to strip put javascript , style , html tags and multi-line comments. There are many ways, to go a head for this approach&#8230;</p>
<blockquote><p>&lt;?<br />
function stripTags($variable){<br />
$searchForm = array(&#8216;@&lt;script[^&gt;]*?&gt;.*?&lt;/script&gt;@si&#8217;,<br />
&#8216;@&lt;style[^&gt;]*?&gt;.*?&lt;/style&gt;@siU&#8217;,<br />
&#8216;@&lt;[\/\!]*?[^&lt;&gt;]*?&gt;@si&#8217;,<br />
&#8216;@&lt;![\s\S]*?&#8211;[ \t\n\r]*&gt;@&#8217;<br />
);<br />
$output = preg_replace($searchForm, &#8221;, $variable);<br />
return $output;<br />
}<br />
?&gt;</p></blockquote>
<p>Let me explain the above code in depth, such that no voice programmers may find useful. The first line is where you define your function and followed by array. The array contains list of regular expressions, what does these do? I will go in sequential way.</p>
<p><strong>1. It blocks out the Javascript.<br />
2. The style codes are blocked.<br />
3. Stripping out the HTML tags.<br />
4. Stripping out multiline comments, including CDATA.</strong></p>
<p>The you come up with preg_replace, which performs a regular expression search and replace and you get the outout finally.</p>
<p>Finally, the real coding mela. Now let me write a code which you can use it various places, checking many stuffs. I think RajiniKanth movie also goes in such a way, the climax always better and better with rocking style. Here i go with another mottai boss style.</p>
<blockquote><p>&lt;?<br />
function sanitizing($theInput){<br />
if(is_array($theInput){<br />
foreach($theInput as $variable=&gt;$value) {<br />
$output[$variable]=santizing($value);<br />
}<br />
}<br />
else{<br />
if(get_magic_quotes_gpc()){<br />
$theInput = stripslashes($theInput);<br />
}<br />
$theInput = stripTags($theInput);<br />
$output = mysql_real_escape_string($theInput);<br />
}<br />
return $output;<br />
}<br />
?&gt;</p></blockquote>
<p>Now from here, lets take an example on how to use the above function in our code.</p>
<blockquote><p>&lt;?<br />
$string = &#8220;Howdy Vinothbabu &lt;script src=&#8217;filename.js&#8217;&gt;&lt;/script&gt; It&#8217;s so cool!&#8221;;</p>
<p>$_POST = sanitizing($_POST);<br />
$_GET  = sanitizing($_GET);<br />
$output = sanitizing($string);<br />
?&gt;</p></blockquote>
<p>The above code will return Howdy Vinothbabu It\&#8217;s so cool! Now lets take a break, by having a cigar and tea and jump into the part how the code works and what are the above methods. Let me explain you in my BOSS [ <strong>Superstar RajiniKanth</strong>] Style.</p>
<p>The first thing we are doing is adding a backslash before any of the following: ‘ (single-quote), “ (double quote), \ (backslash) and NULL characters.The <strong>get_magic_quotes_gpc</strong> returns 0[Off] or 1[On], depending upon your php.ini. If its turned ON, then strip all the blackslash&#8230; the single \ will be removed and \\ will be converted into one.</p>
<p>Normally, we have to take care using <strong>stripslashes</strong>, if the text we insert into our db contains \n, then you will encounter it as n instead of \n. Now comes the next line, where we have called our successor function <strong>stripTags</strong>() which will strip out the Tags. The final one is mysql_real_escape_string(). I think some may be thinking, where did <strong>addslashes </strong>move away, i would stop here on going further with a debate on which is better, i prefer mysql_escape_string as it sounds good. Using <strong>mysql_real_escape_string() </strong>around each variable prevents SQL Injection.</p>
<p><strong>Conclusion: </strong></p>
<p>PHP is secure language, if the programmers do take care of such nitchy things while coding. I have always felt the heat when someone says PHP is not secure, its all left in the hand of developers while coding. I hope you people enjoy reading my article.</p>
]]></content:encoded>
			<wfw:commentRss>http://httpguru.com/featured/sanitizing-your-database-inputs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>email Injection &#8211; How to prevent it?</title>
		<link>http://httpguru.com/php-mysql/email-injection-how-to-prevent-it/</link>
		<comments>http://httpguru.com/php-mysql/email-injection-how-to-prevent-it/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 09:46:37 +0000</pubDate>
		<dc:creator>Vinothbabu</dc:creator>
				<category><![CDATA[PHP & MySQL]]></category>

		<guid isPermaLink="false">http://httpguru.com/?p=153</guid>
		<description><![CDATA[I persume that most of them would be knowing this attack and how to prevent it, but recently when i was googling i found out many feedback form scripts to be in secure. PHP is a majuscule and secure language, but it all depends upon the programmer style of coding. Anyway lets get started&#8230; 
If [...]]]></description>
			<content:encoded><![CDATA[<p>I persume that most of them would be knowing this attack and how to prevent it, but recently when i was googling i found out many feedback form scripts to be in secure. PHP is a majuscule and secure language, but it all depends upon the programmer style of coding. Anyway lets get started&#8230; <span id="more-153"></span></p>
<p>If you are on the way of writing your own form, make sure you indite in such a way that spammers dont hijack it and spam others using your form.Normally we use PHP&#8217;s mail() function to send email. Our script may contain the below code.</p>
<blockquote><p>mail(&#8221; yourname@emailaddress.com&#8221;, &#8221; Title &#8220;, $msg, &#8220;From: $emailAddr&#8221;);</p></blockquote>
<p>The above does nothing new, just the traditional approach where <strong>yourname@emailaddress.com</strong> is the webmasters or receivers address and the sender address info would be in $emailAddr variable. Now lets come to attack, hopefully you can take a good look from here.</p>
<p>If you don&#8217;t sanitize the $emailAddr variable before calling the mail(), then the attacker can inject additional headers into your messages by placing lines in $emailAddr variable.</p>
<p>What does this <strong>sanitize </strong>mean in general &#8211; Well, for one, you’re going to inspect the data and make sure that it doesn’t contain any malicious code.</p>
<blockquote><p>some-email-address@emailaddress.com<br />
CC: another-email-address@emailaddress.com, yet-another-email-addresses@emailaddress.com, etc-etc@emailaddress.com</p></blockquote>
<p>The mail() function will insert these lines into your header and pass it to the mail agent, which will deliver the mail to everyone in the list. Now your form is hijacked and you have been a victim of someones attack.</p>
<p><strong>Prevention is better than cure</strong></p>
<p>Now lets look on how to make our script secure, by preventing this attack.There are chances where you have to look that the user has not entered any malicious javascript code. There are many ways and lots of attack to be prevented, but for now lets look on this alone.</p>
<blockquote><p>if ( ereg( &#8220;[\r\n]&#8220;, $name ) || ereg( &#8220;[\r\n]&#8220;, $emailAddr ) ) {</p>
<p>redirect the user to error page and note down the IP address.</p>
<p>}</p></blockquote>
<p>$name will hold the visitors name and $emailAddr will contain the visitors email address. The function ereg will help us to find if there is a new line characters. The characters like carriage return[ \r ] and line feed [ \n ] creates a new line in email headers which will allow for a new CC: line. Now our code will detect if there is a new line, if it is then the user is directed to an error page. Make sure you prevent this attackm else your script might inadvertantly be abused to send spam to others without your knowing.</p>
]]></content:encoded>
			<wfw:commentRss>http://httpguru.com/php-mysql/email-injection-how-to-prevent-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shared Objects in Flex</title>
		<link>http://httpguru.com/adobe-galla/adobe-flex/shared-objects-in-flex/</link>
		<comments>http://httpguru.com/adobe-galla/adobe-flex/shared-objects-in-flex/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 18:52:09 +0000</pubDate>
		<dc:creator>Vinothbabu</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://httpguru.com/?p=149</guid>
		<description><![CDATA[How nice it would be to welcome back or to recognize visitors who are revisiting your website or application. Adobe Flex provides ways to store objects in clients machine, and implementing does not compromise any issues on security of the client&#8217;s machine.
The Behaviour of shared objects is somewhat like a cookie. The class can be [...]]]></description>
			<content:encoded><![CDATA[<p>How nice it would be to welcome back or to recognize visitors who are revisiting your website or application. Adobe Flex provides ways to store objects in clients machine, and implementing does not compromise any issues on security of the client&#8217;s machine.<span id="more-149"></span></p>
<p>The Behaviour of shared objects is somewhat like a cookie. The class can be used to store data on the clients machine and retrive those objects in same session or in another session. The declaration part is as simple like Arrays , String or Date. You are also allowed to create multiple instance in one application and each instance is associated with a name to identify.Don&#8217;t worry readers, at the end i will provide you with an example.</p>
<blockquote><p>private function visitingInfo():void<br />
{<br />
var dateInfo:SharedObject = SharedObject.getLocal(”userVisitedDate”);<br />
trace(&#8220;SharedObject is &#8221; + dateInfo.size + &#8221; bytes&#8221;);<br />
if(dateInfo.data.lastVisitedDate != null)<br />
{<br />
Alert.show(”Welcome back, you visited last on ” + dateInfo.data.lastVisitedDate);<br />
}<br />
dateInfo.data.lastVisitedDate = new Date();<br />
dateInfo.flush();<br />
}</p></blockquote>
<p>Let me explain the code to you in brief. Initially we are creating a variable of return type sharedObject. The getLocal method tried to load a local shared Object with the name <strong>lastVisitedInfo.</strong> If there is no name, then a new object is created. Now in the coming line, we are checking whether it is is NULL and displaying an appropriate message. The final line is makes sure that your object is saved.</p>
]]></content:encoded>
			<wfw:commentRss>http://httpguru.com/adobe-galla/adobe-flex/shared-objects-in-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging in PHP &#8211; Part 1</title>
		<link>http://httpguru.com/php-mysql/debugging-in-php-part-1/</link>
		<comments>http://httpguru.com/php-mysql/debugging-in-php-part-1/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 06:38:35 +0000</pubDate>
		<dc:creator>Vinothbabu</dc:creator>
				<category><![CDATA[PHP & MySQL]]></category>

		<guid isPermaLink="false">http://httpguru.com/?p=145</guid>
		<description><![CDATA[Debugging is most important in development as it saves your countless hours of coding. Lets explore the various debugging techniques. 
1. The basic includes turning on error reporting.
2. The next one involves using print statements. This help you identify elusive bugs by displaying what is actually going on your screen.
3. This one is what i [...]]]></description>
			<content:encoded><![CDATA[<p>Debugging is most important in development as it saves your countless hours of coding. Lets explore the various debugging techniques. <span id="more-145"></span></p>
<p>1. The basic includes turning on error reporting.</p>
<p>2. The next one involves using print statements. This help you identify elusive bugs by displaying what is actually going on your screen.</p>
<p>3. This one is what i currently play with PHPeclipse which is an Eclipse Plug, that can highlight comman errors and also can be used as a debugger setting up breakpoints. Those who have played J2ee development, would be knowing it much better.</p>
<p>Now lets jump on each of these for a better construing. Its always the best practice to keep error reporting ON while on development mode, as it acts as a defence for developers like us. Make sure its off while the code is in production environment, as you don&#8217;t want your visitors to track the error which may lead him to get some loop holes for attacks.</p>
<p><strong>Error reporting via PHP</strong></p>
<p>I hope you would have come across php.in file. This is a configuration file which is used to control some of settings of PHP interpreter. I am in the progress of writing a detailed explanation on what exactly this php.ini is how we can play with it. Keep watching the site for updates. So lets come back to the game, you may notice these few lines in your php.ini file.</p>
<blockquote><p>display_errors = Off<br />
error_reporting = E_ALL</p></blockquote>
<p>The main purpose of display_errors varibale is to whether you want to show errors or not. To make life easier set it ON while you are in development mode. What&#8217;s all about error_reporting. This displays everything from bad coding practices to harmless notices to errors. basically i would set it as something like this to avoid harmless notices, like uninitialized variables.</p>
<blockquote><p>error_reporting = E_ALL &amp; ~E_NOTICE</p></blockquote>
<p>Now restart your apache, and the get start go. Now how about if you don&#8217;t have the permissions in your php.ini file. Don&#8217;t get fret, here is how we go again.</p>
<blockquote><p> &lt;?php<br />
error_reporting  (E_ALL);<br />
ini_set (&#8216;display_errors&#8217;, true);<br />
include(&#8216;./filename.php&#8217;);<br />
?&gt;</p></blockquote>
<p><strong>Error reporting in the server</strong></p>
<p>Sometimes it happens as you might not know which php is your apache pointing as there may be multiple versions. To do the same as you just did in the php.ini file, add the following lines to your httpd.conf to override any and all php.ini files:</p>
<blockquote><p>php_flag  display_errors        on<br />
php_value error_reporting       2039</p></blockquote>
<p>This will ensure you that, the above configuration overrides your php.ini file making the defualt value changed. I know your head might poggle up up on the number 2039. Its nothing but, setting up E_ALL &amp; ~E_NOTICE both, if you just want E_ALL alone then go for 2047.</p>
<p><a name="N10126"><span class="atitle"><strong>Introducing print statements</strong></span></a></p>
<p>Functional bugs don&#8217;t generate bugs, its always tricky to get those errors placing print or die statement to juggle out. Sometimes your business logic my syntactically correct, but they are functionality bugs. These are really hard, as these type of errors are not thrown.The <code>die()</code> statement halts program execution and displays text to the Web browser. The <code>die()</code> statement is particularly useful if you don&#8217;t want to have to comment out your code, and you only want everything up to the error and the error displayed and nothing after.</p>
<blockquote><p> foreach($_GET as $abc =&gt; $i){<br />
     <strong>print(&#8220;What is the data &#8221; . $_GET[$abc "&lt;br&gt;");<br />
</strong> }</p></blockquote>
<p>Now here, you could notice what is printed in $_GET[$abc]. Now here you can notice whether the values are printed correctly inside a loop making further efficient way using print statement.</p>
<p>In my next part, i will explain you how to play with phpeclipse and built in xdebug for debugging. I hope this small article may come in handy for new comers to PHP world.</p>
]]></content:encoded>
			<wfw:commentRss>http://httpguru.com/php-mysql/debugging-in-php-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autoloading objects &#8211; an overview</title>
		<link>http://httpguru.com/php-mysql/autoloading-objects-an-overview/</link>
		<comments>http://httpguru.com/php-mysql/autoloading-objects-an-overview/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 09:43:45 +0000</pubDate>
		<dc:creator>Vinothbabu</dc:creator>
				<category><![CDATA[PHP & MySQL]]></category>

		<guid isPermaLink="false">http://httpguru.com/?p=139</guid>
		<description><![CDATA[One of my amigo last week put up a question towards me seeking a clear riposte on what&#8217;s exactly this autoloading does. I thought of putting this up here on what i scribbled in the piece of paper to explain him.
What is Autoloading objects?
How about we including the classes automatically. puzzled right! Normally to include [...]]]></description>
			<content:encoded><![CDATA[<p>One of my amigo last week put up a question towards me seeking a clear riposte on what&#8217;s exactly this autoloading does. I thought of putting this up here on what i scribbled in the piece of paper to explain him.<span id="more-139"></span></p>
<p><strong>What is Autoloading objects?</strong></p>
<p>How about we including the classes automatically. puzzled right! Normally to include a class, you would go on with either ( include or require ) languager construct. By using <code>__autoload</code> function defined, inclusion will handle itself. I will explain you clearly further citing the traditional way as well as new approach.</p>
<p><strong>Traditionally we would go in this fashion</strong></p>
<blockquote><p>include &#8220;classes/class.vinoth.php&#8221;;</p>
<p>$vinoth = new Vinoth;<br />
$vinoth-&gt;methodname();</p></blockquote>
<p><strong>With our new approach&#8230;.</strong></p>
<blockquote><p>function <code>__autoload</code>($class_name)<br />
{<br />
require_once $DOCUMENT_ROOT.“classes/class.”.$class_name.“.php”;<br />
}<br />
$vinoth = new Vinoth;<br />
$vinoth-&gt;methodname();</p></blockquote>
<p>Here, if Vinoth is created for the first time then the <code>__autoload function is called automatically.</code>Normally everydevelopers follow their own style of coding. I have used autoload in a different fashion irrespective of the listed above. I normally set the ini_set or set_include_path before hand and make the <code>__autoload function much simpler just including the class name.</code></p>
<p><strong>Note</strong>: We can also make throw expections instead of fatal error, if the classes are not loaded.</p>
]]></content:encoded>
			<wfw:commentRss>http://httpguru.com/php-mysql/autoloading-objects-an-overview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP with AJAX &#8211; Introduction</title>
		<link>http://httpguru.com/javascript-ajax/php-with-ajax-introduction/</link>
		<comments>http://httpguru.com/javascript-ajax/php-with-ajax-introduction/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 23:31:04 +0000</pubDate>
		<dc:creator>Vinothbabu</dc:creator>
				<category><![CDATA[JavaScript & Ajax]]></category>
		<category><![CDATA[PHP & MySQL]]></category>

		<guid isPermaLink="false">http://httpguru.com/?p=130</guid>
		<description><![CDATA[As I am celeberating my fifth year in a row working with PHP. It has been a great experiece, and i remember those days of PHP where it was revolving OOP concept to the latest ones which puts PHP in a place competiting with JAVA, dotnet and others. Anyway lets start as usual in RajiniKanth [...]]]></description>
			<content:encoded><![CDATA[<p>As I am celeberating my fifth year in a row working with PHP. It has been a great experiece, and i remember those days of PHP where it was revolving OOP concept to the latest ones which puts PHP in a place competiting with JAVA, dotnet and others. Anyway lets start as usual in RajiniKanth style.<span id="more-130"></span></p>
<p><strong>Before going further&#8230; let me put what&#8217;s actually PHP and Ajax are all about.</strong></p>
<p><strong>PHP &#8211; &gt; Taken from PHP website.<br />
</strong></p>
<p><acronym title="PHP: Hypertext Preprocessor"></acronym>PHP(recursive acronym for &#8220;PHP: Hypertext     Preprocessor&#8221;) is a widely-used open source general-purpose     scripting language that is especially suited for web     development and can be embedded into HTML.</p>
<p><strong>AJAX &#8212; &gt; From the Web</strong></p>
<p>Ajax, or AJAX (Asynchronous JavaScript and XML), is a group of interrelated web development techniques used to create interactive web applications or rich Internet applications.</p>
<p>Lets start with some coding, so that you can put your speakers loud enough hearing RajiniKanth&#8217;s music as its going to be damm sweet and easy while we go through.</p>
<blockquote><p>&lt;?php<br />
session_start();<br />
$arrayNames = array(&#8216;Preeti&#8217;,'Kajol&#8217;,'Vinoth&#8217;,'Nayantara&#8217;,'Sandya&#8217;,'Priya&#8217;,'Reenga&#8217;);</p>
<p>if(in_array($_GET['name'], $arrayNames)) {<br />
echo &#8216;1&#8242;;<br />
}<br />
else {<br />
echo &#8216;0&#8242;;<br />
}<br />
?&gt;</p></blockquote>
<p>You are starting the session initially, with this you are declaring array of names and storing it in a variable $arrayNames. if the names are available, we print out 1 and else its 0.</p>
<p>Now a Question might araise how are we checking and where are we. Wait dude&#8230; check down below which you will explain you the rest. For now remember the <strong>$_GET['name']. </strong>We are getting this ID from the indexpage and then checking it with the list of names here and printing one or zero based on that.</p>
<p>Let me explain each and every line, so it will make more clear on whats happening here. Don&#8217;t worry amigos, you will get a example at the very end. <strong>RajiniKanth&#8217;s movie always ends in a happy climax.</strong></p>
<blockquote><p>var ajaxObj=false;</p></blockquote>
<p>We set the ajaxObj as false by defual and later it changes.</p>
<blockquote><p>function ajaxMethod(url){<br />
if(window.XMLHttpRequest){<br />
ajaxObj= new XMLHttpRequest();<br />
if(ajaxObj.overrideMinmeType){<br />
ajaxObj.overrideMinmeType(&#8216;text/xml&#8217;);<br />
}<br />
}</p></blockquote>
<p>We are then moving to this function where we are checking what the browser is and then creating the required Object. Let me go further deeper.</p>
<blockquote><p>function ajaxMethod(url){</p></blockquote>
<p>Name of the function and it holds a parameter url which will be passed during the time of function call.</p>
<blockquote><p>if(window.XMLHttpRequest){</p></blockquote>
<p>If the browsing window is   Firefox , Safari or IE 7.0 then we get here and then create a new <strong>XMLHttpRequest </strong>object. <strong>So what is this XMLHttpRequest?</strong></p>
<blockquote><p>ajaxObj= new XMLHttpRequest();</p></blockquote>
<p><strong>XMLHttpRequest </strong>(XHR) is a DOM API that can be used by JavaScript and other web browser scripting languages to transfer XML and other text data between a web server and a browser.</p>
<blockquote><p>if(ajaxObj.overrideMinmeType){<br />
ajaxObj.overrideMimeType(&#8216;text/xml&#8217;);</p></blockquote>
<p>The older version of Mozila needs some help from our coders to understand the Request which we are passing. The <strong>overrideMimeType </strong>will force the XMLHTTPRequest to parse it as XML anyway, if the server does not support test/xml content type header.</p>
<blockquote><p>else if(window.ActiveXObject){<br />
try{<br />
ajaxObj= new ActiveXObject(&#8220;Msxml2.XMLHTTP&#8221;);<br />
}catch (e){<br />
try{<br />
ajaxObj= new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;);<br />
}catch(e){}<br />
}<br />
}</p></blockquote>
<p>Here we are checking if its Microsoft Internet explorer 6.0 and then creating the new ActiveXObject. Don&#8217;t worry though the process is same as above. There are few terms which would be nice if its also explained. Let me first go with ActiveXObject.</p>
<p>The <strong>ActiveXObject </strong>is use to enable and return a reference to an Automation object.An object that is exposed to other applications or programming tools through Automation interfaces. People say using ActiveXObject is dangerous as it allows access to operating system from outside the browser sandbox.</p>
<p><strong>Msxml2.XMLHTTP and Microsoft.XMLHTTP</strong></p>
<p>Actually to say there is no difference, Microsoft decided to change the namespace and they both will instantiate the same version of MSXML object which could be of any versions 2, 2.6 or 3.0</p>
<blockquote><p>if(!ajaxObj){<br />
alert(&#8220;your browser does not support&#8221;);<br />
return false;<br />
}</p></blockquote>
<p>Do we need explantion? yes if this prints out then make sure that the version you use does not support. Upgrade to the newer version. <strong>I would say IE 7.0 or IE 8.0 beta.</strong></p>
<blockquote><p>ajaxObj.onreadystatechange = ajaxRes;<br />
ajaxObj.open(&#8216;GET&#8217;, url, true);</p>
<p>ajaxObj.send(null);<br />
return true;<br />
}</p></blockquote>
<p>onreadystatechange event handler is fired when the state is 4. This property is an event handler which is triggered whenever the state of the request changes. The states run from zero (uninitialized) through to four (complete).</p>
<blockquote><p>ajaxObj.open(&#8216;GET&#8217;, url, true);<br />
ajaxObj.send(null);</p></blockquote>
<p>The open method here makes the request to the server with the url which is passed during the function call time. It takes <strong>three parameters</strong>. The first one is the request type which is either GET or POST. The second one is the url of the server side process and the third defines whether the call will be asynchronous (true) or synchronous (false).</p>
<p><strong>Asynchronous </strong>means the processing will happen without waiting for the server side retrieval to complete and where as <strong>synchronous </strong>call would stop all other processing and wait for the response from the server.</p>
<p>the event handler is defined and we are ready to send our request to the server which is done by the <strong>send </strong>method.</p>
<blockquote><p>function ajaxRes() {<br />
if(ajaxObj.readyState == 4) {<br />
if(ajaxObj.status == 200) {<br />
if(ajaxObj.responseText == &#8216;1&#8242;){<br />
alert(&#8216;Its seems to be ok&#8217;);<br />
}<br />
else {<br />
alert(&#8216;I think you are not known&#8217;);<br />
}<br />
}<br />
else {<br />
alert(&#8216;it seems there is some other error&#8217; + ajaxObj.status.toString() + &#8216;.&#8217;);<br />
return;<br />
}<br />
}<br />
}</p></blockquote>
<p>The <strong>readyState </strong>property holds the status of the server&#8217;s response. Each time the readyState changes,  the onreadystatechange function will be executed.</p>
<table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#993300" class="ex" id="table7">
<tbody>
<tr>
<td><span class="style5">0</span></td>
<td><span class="style5">The request is not initialized</span></td>
</tr>
<tr>
<td><span class="style5">1</span></td>
<td><span class="style5">The request has been set up</span></td>
</tr>
<tr>
<td><span class="style5">2</span></td>
<td><span class="style5">The request has been sent</span></td>
</tr>
<tr>
<td><span class="style5">3</span></td>
<td><span class="style5">The request is in process</span></td>
</tr>
<tr>
<td><span class="style5">4</span></td>
<td><span class="style5">The request is complete</span></td>
</tr>
</tbody>
</table>
<p></p>
<p>The data sent back from the server can be retrieved with the <strong>responseText </strong>property.</p>
<p>The Tutorial has come to finale, and it seems the hands are itching to test the code and check for a demo. <strong>As i said, RajiniKanth fans or movie never dissappoints anyone.</strong></p>
<p><a href="http://www.httpguru.com/downloads/ajaxTut.rar">Download </a> the Code and Check the <a href="http://www.httpguru.com/demo/ajaxTut/">Demo</a> Here.</p>
]]></content:encoded>
			<wfw:commentRss>http://httpguru.com/javascript-ajax/php-with-ajax-introduction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
