<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.1" -->
<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/"
	>

<channel>
	<title>Welcome to the world of PHP</title>
	<link>http://www.php-bloggersplace.org</link>
	<description>PHP Blog &#124; Learn PHP Tricks</description>
	<pubDate>Mon, 30 Jun 2008 11:09:09 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1</generator>
	<language>en</language>
			<item>
		<title>Improve your engine performance and environment by running your car on water</title>
		<link>http://www.php-bloggersplace.org/2008/06/30/improve-performance/</link>
		<comments>http://www.php-bloggersplace.org/2008/06/30/improve-performance/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 10:36:32 +0000</pubDate>
		<dc:creator>passion@php</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.php-bloggersplace.org/2008/06/30/popularity-of-uk-gambling-site/</guid>
		<description><![CDATA[If you are willing to modify your gasoline engine so that it can run on water, you simply need a few additional arrangements so that water gets electrolyzed in an outer chamber and through the connecting arrangements the gases produced from it are passed to the combustion chamber. Water dissociates into two atoms of hydrogen [...]]]></description>
			<content:encoded><![CDATA[<p>If you are willing to modify your gasoline engine so that it can run on water, you simply need a few additional arrangements so that water gets electrolyzed in an outer chamber and through the connecting arrangements the gases produced from it are passed to the combustion chamber. Water dissociates into two atoms of hydrogen and one atom of oxygen during electrolysis, and these free atoms chemically combine through coordinate bonds to form hydrogen and oxygen gases molecules. </p>
<p>The hydrogen gas is much more efficient and it has higher calorific value than gasoline and it produces water after combustion. The water produced during combustions will keep down the temperature of your car engine. As the temperature is low within the car engine, the other problems associated with it also get minimized. Further hydrogen does not produce sludge, varnish or soot during combustion so it also helps in cleaning engine parts. The wear and tear of the engine parts is more common at higher temperature and in presence of sludge, varnish or soot, however if the temperature is low and the oxidation products of gasoline and diesel are minimum, the wear and tear of engine parts is also minimum.</p>
<p>Generally the conventional fuels such as gasoline or diesel after burning in combustion chambers emits particulate matter, un-burnt hydrocarbon vapors, oxides of sulfur and oxides of nitrogen are also emitted if the engine temperature goes beyond a particular temperature. A lot of carbon dioxide also emitted and which is causing a damage to our environment vigorously. Some of these gases and particularly carbon dioxide contribute in global warming and therefore polluting our environment rapidly.</p>
<p> If you run your car on water, you send hydrogen and oxygen mixture in the combustion chamber of your car and hydrogen on burning gives only water. This water keeps the temperature of engine down and therefore reduces the chances of NOx formation within the combustion chamber. As hydrogen is a clean fuel, it do not produce oxides of sulfur and nitrogen and therefore it’s more and more use will ensure the safe and protected environment for years to come.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-bloggersplace.org/2008/06/30/improve-performance/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP and Ajax:  An Introduction</title>
		<link>http://www.php-bloggersplace.org/2007/12/08/php-and-ajax-an-introduction/</link>
		<comments>http://www.php-bloggersplace.org/2007/12/08/php-and-ajax-an-introduction/#comments</comments>
		<pubDate>Sat, 08 Dec 2007 09:29:12 +0000</pubDate>
		<dc:creator>passion@php</dc:creator>
		
		<category><![CDATA[PHP Basics]]></category>

		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://www.php-bloggersplace.org/2007/12/08/php-and-ajax-an-introduction/</guid>
		<description><![CDATA[Introduction
Ajax is an acronym for Asynchronous Javascript and XML. It is basically a cross-platform mechanism which allows you to make fast, rich and responsive web pages. Using AJAX a coder can avoid reloading the web page  when a part of it is changing because of the user interaction. So the AJAX engine which runs [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p align="justify">Ajax is an acronym for Asynchronous <em>Javascript</em> and <em>XML</em>. It is basically a cross-platform mechanism which allows you to make fast, rich and responsive web pages. Using AJAX a coder can avoid reloading the web page  when a part of it is changing because of the user interaction. So the <strong>AJAX</strong> engine which runs within the context of the browser  handles basic tasks of validation and oter changes while the script dynamically retrieve some data from the application. This data transfer happens from browser to application in the background and so known as ‘Asynchronous mode of execution’.</p>
<h3>Dynamic Script Loading</h3>
<p align="justify">An alternate to XMLHTTP is dynamic script loading. It has a simple mechanism:  you write a javascipt file and in your code you put a &lt;script/> tag and assign the javascript file to its ‘src’ attribute so that it can be loaded when required. The following code explains this:</p>
<p><code><br />
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"<br />
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><br />
&lt;html xmlns="http://www.w3.org/1999/xhtml"><br />
  &lt;head><br />
    &lt;title>Example 1</title><br />
    &lt;script type=&#8221;text/javascript&#8221;>//<![CDATA[<br />
        function makeRequest() {<br />
          var oScript = document.createElement("script");<br />
          oScript.src = "example1.js";<br />
          document.body.appendChild(oScript);<br />
        }</p>
<p>        function callback(sText) {<br />
          alert("Loaded from file: " + sText);<br />
        }<br />
    //]]&gt;<br />
    &lt;/script><br />
  &lt;/head><br />
  &lt;body><br />
    &lt;input type=&#8221;button&#8221; value=&#8221;Click Me&#8221; onclick=&#8221;makeRequest()&#8221; /><br />
  &lt;/body><br />
&lt;/html><br />
</code></p>
<p align="justify">So you can see the &lt;script/> element is created using the <strong>DOM</strong> createElement() method and add it to the page.</p>
<p>var oScript = document.createElement(&#8221;script&#8221;);<br />
oScript.src = &#8220;/path/to/my.js&#8221;;<br />
document.body.appendChild(oScript);</p>
<p align="justify">When the new &lt;script/> element is actually added to the page then only downloading starts. Once downloading is done the JavaScript code is interpreted. The callback function is used to indicate that the code has finished being loaded and interpreted.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-bloggersplace.org/2007/12/08/php-and-ajax-an-introduction/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP Date and Time Functions and Time Zones</title>
		<link>http://www.php-bloggersplace.org/2007/12/04/php-date-and-time-functions-and-time-zones/</link>
		<comments>http://www.php-bloggersplace.org/2007/12/04/php-date-and-time-functions-and-time-zones/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 19:43:31 +0000</pubDate>
		<dc:creator>passion@php</dc:creator>
		
		<category><![CDATA[PHP Basics]]></category>

		<category><![CDATA[date and time]]></category>

		<guid isPermaLink="false">http://www.php-bloggersplace.org/2007/12/04/php-date-and-time-functions-and-time-zones/</guid>
		<description><![CDATA[Introduction
These functions are basic tools used in many self-defined functions. PHP date and time functions are pretty straightforward to use if you understand the UNIX timestamp. They fall into three categories: returns the date or time, formats date or time, and validates date. UNIX timestamp measures time as a number of seconds since the beginning [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p align="justify">These functions are basic tools used in many self-defined functions. PHP <em>date and time</em> functions are pretty straightforward to use if you understand the UNIX timestamp. They fall into three categories: returns the date or time, formats date or time, and validates date. UNIX timestamp measures time as a number of seconds since the beginning of the UNIX epoch(midnight Greenwich Mean Time on January 1, 1970). </p>
<h3>Functions Returning the date and time</h3>
<p align="justify">The fastest way to get a time is to use the <strong>time()</strong> function. This will return the <strong>UNIX timestamp</strong> for your locale. If you pass this <em>timestamp</em> to another function or program then it is the best format. But if you want to make human-readable, you have to format it. </p>
<p align="justify">If you want to measure performance the best utility to be used is <strong>microtime()</strong> function which returns the current time in seconds and microseconds since the UNIX epoch.</p>
<p align="justify">The main function used to return a date is getdate($timestamp). When used with the argument <strong>time()</strong>, as in getdate(time()), it returns an associative array with the following numeric elements derived from the UNIX timestamp – </p>
<p align="justify">seconds, minutes, hours, mday: day of the month(1-31), wday: day of the week(1-7), mon: month(1-12),year, yday: day of the year(1-365), weekday: day of the week( Sunday – Saturday) and month(January – December).</p>
<p align="justify">The date() function gives you the date and format it in one step. Without the timestamp as argument it returns you the current local date.</p>
<h3>Functions Formatting the date and time</h3>
<p align="justify">The main method to format a timestamp is using date($format&#8230;.   $formatn[,$timestamp]). You pass a series of code indicating your formatting preferences, plus an optional timestamp.</p>
<p align="justify">The function <strong>strftime($format&#8230;.   $formatn[,$timestamp])</strong> is similar but specializes in formatting the time rather than date. The function gmstrftime($format&#8230;.   $formatn[,$timestamp]) returns the time in formatted Greenwich Mean Time.</p>
<p align="justify">The function <strong>mktime()</strong> allows you to convert any date into a timestamp. It’s subtly different in the ordre of arguments from the UNIX command of the same name. The function gmmktime() gives the <em>Greenwich Mean time</em>.</p>
<p align="justify">Finally, the checkdate($month, $day, $year) allows you to quickly ensure that a particular date is a valid one, which is great help on leap-year questions.</p>
<h3>User defined time zones</h3>
<p align="justify">Problems occur when you take time and date information form an user whose time zone  is not same as the time zone of the server.  To convert this you need to have a location independent format for storing time in database and then again translate that to user’s local time. For that Greenwich Mean Time based <em>timestamp</em> is most neutral.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-bloggersplace.org/2007/12/04/php-date-and-time-functions-and-time-zones/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Functions and Variables Scope in PHP</title>
		<link>http://www.php-bloggersplace.org/2007/12/04/functions-and-variables-scope-in-php/</link>
		<comments>http://www.php-bloggersplace.org/2007/12/04/functions-and-variables-scope-in-php/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 19:40:25 +0000</pubDate>
		<dc:creator>passion@php</dc:creator>
		
		<category><![CDATA[PHP Basics]]></category>

		<category><![CDATA[functions]]></category>

		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.php-bloggersplace.org/2007/12/04/functions-and-variables-scope-in-php/</guid>
		<description><![CDATA[Introduction
Scope is a technical term for the rules stating when a name (for a variable or function or any object) has the same meaning in two different places  and when they mean differently.
Variable Scope
Any PHP variable that is not inside a function has global scope and extends throughout a given thread of execution. i.e., [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p align="justify">Scope is a technical term for the rules stating when a name (for a <strong>variable</strong> or <strong>function</strong> or any object) has the same meaning in two different places  and when they mean differently.</p>
<h3>Variable Scope</h3>
<p align="justify">Any <em>PHP variable</em> that is not inside a function has <em>global scope</em> and extends throughout a given thread of execution. i.e., if you declare the variable at the top of a PHP file, it has the same meaning at end of the file and if not reassigned it will hold the same value. When you declare and assign a variable inside a PHP page, it assigns and reassigns the variable each time the page executes. Assignments of variables in one file do not affect variables of the same name in a different file , or even in other requests for the same file.</p>
<p align="justify">In some situations when you would like to hold onto information from one page to another you have numerous other techniques for that in PHP. For example, you can pass information from page to page using <strong>GET an POST</strong> variables, store information persistently in a database, associate it with a user session using PHP’s <em>session handling</em> mechanism, or store it in user’s hard disk via a cookie.</p>
<p align="justify">Variables assigned within a function are local to that function, and unless you make a special <em>declaration</em> in a function, that function won’t have access to the global variables declared outside the function. </p>
<h3>Local Scope</h3>
<p align="justify">The basic principle governing variables in function bodies is: each function has its own little world. One variable declared and assigned inside a function has nothing to do outside the function. The only variable values the function has access to are the formal parameter variables and any variable declared within the function. </p>
<p>The following code explains:</p>
<p><code><br />
function myfunc()<br />
{<br />
      $count = 0;<br />
      while($count < 10)<br />
       {<br />
	Print(chr(ord(‘A’) +$count));<br />
	$count = $count + 1;<br />
       }<br />
     Print(“<BR> Counting $count letters”);<br />
}<br />
$count = 0;<br />
myfunc();<br />
$count = $count + 1;<br />
Print(“ I am calling the function for $count times”);<br />
$count = $count + 1;<br />
Print(“ I am calling the function for $count times”);<br />
</code></p>
<p>The output will be:<br />
ABCDEFGHIJ<br />
Counting 10 letters<br />
I am calling the function for 1 times<br />
ABCDEFGHIJ<br />
Counting 10 letters<br />
I am calling the function for 2 times</p>
<p align="justify">Please observe both the <em>function definition</em> and the code outside the function has a variable called $count. But in the file it has file scope and inside the function it has <strong>function scope</strong>. And both are basically pointing to different memory spaces.</p>
<h3>Global versus Local</h3>
<p align="justify">The scope of a variable defined inside a function is local by default.  Using the global  declaration you can inform PHP that you want a variable name to mean the same memory space as it does in the context outside the function. Syntax of this declaration is simply the word global, followed by a comma-delimited list of the variables that should be treated that way. Let us consider a new version of the previous function</p>
<p><code><br />
function myfunc()<br />
{<br />
      global $count;<br />
      while($count < 10)<br />
       {<br />
	Print(chr(ord(‘A’) +$count));<br />
	$count = $count + 1;<br />
       }<br />
     Print(“<BR> Counting $count letters”);<br />
}<br />
$count = 0;<br />
myfunc();<br />
$count = $count + 1;<br />
Print(“ I am calling the function for $count times”);<br />
$count = $count + 1;<br />
Print(“ I am calling the function for $count times”);<br />
</code></p>
<p>The output will be:<br />
ABCDEFGHIJ<br />
Counting 10 letters<br />
I am calling the function for 11 times<br />
Counting 11 letters<br />
I am calling the function for 12 times</p>
<p>This time the control does not go inside the while loop as it is already more than 10.</p>
<h3>Function Scope</h3>
<p align="justify">Functions in PHP scripts must be declared only once somewhere in the script which use them. The scope of function names is implicitly global. It is a good idea to define all the functions to be used before any code which uses them.</p>
<p>The syntax for function declaration:</p>
<p>function function_name(arguments if any) {<br />
	procedures<br />
}  </p>
<p>example:<br />
<code><br />
function HelloJoe($string, $name) {<br />
echo "$string $name";<br />
}<br />
$string = "Hello, ";<br />
$name = "Joe";<br />
HelloJoe($string, $name);<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-bloggersplace.org/2007/12/04/functions-and-variables-scope-in-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Output Buffering</title>
		<link>http://www.php-bloggersplace.org/2007/12/04/output-buffering/</link>
		<comments>http://www.php-bloggersplace.org/2007/12/04/output-buffering/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 19:36:35 +0000</pubDate>
		<dc:creator>passion@php</dc:creator>
		
		<category><![CDATA[PHP Basics]]></category>

		<category><![CDATA[buffering]]></category>

		<guid isPermaLink="false">http://www.php-bloggersplace.org/2007/12/04/output-buffering/</guid>
		<description><![CDATA[Introduction
Output buffering is a comparatively newer concept in PHP. PHP provides some functions which allows a coder to buffer the output from a script and manipulate it in some useful way before sending it to the browser. It solves other problems too, like if you try to set a cookie, or send header information after [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p align="justify"><em>Output buffering</em> is a comparatively newer concept in <strong>PHP</strong>. <strong>PHP</strong> provides some functions which allows a coder to buffer the output from a script and manipulate it in some useful way before sending it to the browser. It solves other problems too, like if you try to set a <em>cookie</em>, or send <em>header information</em> after sending some output PHP generates an error stating &#8220;Cannot modify header information - headers already sent&#8221;. This problem also could be solved using output buffering.</p>
<h3>The Output Buffering in PHP</h3>
<p align="justify">The process of <em>output buffering</em> ensures that no output is send to the visitor of the page until the script ended. Now the problem arises when you have a long-running script, and want some of the output to be flushed to the client, i.e., your browser, PHP output buffering functions allow that. Again you can completely wipe out some of the output from the buffer. Before starting the discussion and see some code, let us have a look in the output buffering functions of PHP.</p>
<p><strong>The functions:</strong></p>
<p>ob_start([callback function]) - Starts an output buffering session.<br />
ob_flush() - Send the contents of the buffer to the client  and clear the buffer.<br />
ob_get_contents() - Returns the contents of the buffer.   The buffer is not cleared.<br />
ob_end_clean() - Ends the current buffering session and purges the buffer.<br />
ob_end_flush() - Ends the current buffering session and displays the buffer.<br />
ob_get_length() - (Version >= 4.0.2) Return the size of the current buffer.<br />
ob_get_clean() - (Version >= 4.3) Composite of ob_get_contents() and ob_end_clean(). The buffer is returned and  the session ends.</p>
<p align="justify">Let us start with a simple program, you want to redirect the user to another site and write the following code</p>
<p><code><br />
&lt;html><br />
&lt;body><br />
&lt;?php<br />
echo "You will now be directed to google.com...\n";<br />
header("Location: http://www.google.com");<br />
?><br />
&lt;/body><br />
&lt;/html><br />
</code></p>
<p align="justify">But this will generate the above mentioned error, as you can not set a cookie or a header after the output have been sent. So the solution would be to hold the output:</p>
<p><code><br />
&lt;?php<br />
//start output buffering<br />
ob_start();<br />
?><br />
&lt;html><br />
&lt;body><br />
&lt;?php<br />
echo "You will now be directed to google.com...\n";<br />
header("Location: http://www.google.com");<br />
?><br />
&lt;/body><br />
&lt;/html><br />
&lt;?php<br />
//send the contents of the buffer to the browser<br />
ob_end_flush();<br />
?><br />
</code></p>
<p align="justify">Next a <strong>callback function</strong> could be used with output buffering. It is probably the most powerful help of  <em>output buffering</em> that is cn define a  callback functions. Using this you can define a callback function and this function will be called only when the buffer is flushed. This function takes the buffer as a parameter. The value returned by the function is printed in the output.</p>
<p><code><br />
&lt;?php<br />
function my_callback($content) {<br />
        $content = ' Will Smith';<br />
        return $content;<br />
}<br />
// Start output buffer with callback<br />
ob_start('my_callback');<br />
echo 'Hello';<br />
?><br />
</code></p>
<p>So the output will be Hello Will Smith</p>
<p align="justify">By this time you must have understood, that the <strong>ob_start()</strong> function creates a buffer (imagine it as a very long string, capable of storing lots of output) and starts buffering, and <strong>ob_end_flush()</strong> function flushes it out. The function ob_clean() is capable of cleaning the buffer if required and <strong>ob_flush()</strong> flushes it in the browser. Now, you can create more than one buffer in the script and nest them too. Before ending this discussion let us look into a nested buffer. The code is self explanatory.</p>
<p><code><br />
&lt;?php<br />
// Open buffer #1<br />
ob_start();<br />
print "Line 1\n";<br />
// Open buffer #2<br />
ob_start();<br />
print "Line 2\n";<br />
// Grab the contents of buffer #2<br />
$buf2 = ob_get_contents();<br />
// Close buffer #2<br />
ob_end_clean();<br />
print "Line 3\n";<br />
// Grab the contents of buffer #1<br />
$buf1 = ob_get_contents();<br />
// Close buffer #1<br />
ob_end_clean();<br />
// Output the buffer contents<br />
print $buf1;<br />
print $buf2;<br />
?><br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-bloggersplace.org/2007/12/04/output-buffering/feed/</wfw:commentRss>
		</item>
		<item>
		<title>REST, XML-RPC, SOAP</title>
		<link>http://www.php-bloggersplace.org/2007/11/25/rest-xml-rpc-soap/</link>
		<comments>http://www.php-bloggersplace.org/2007/11/25/rest-xml-rpc-soap/#comments</comments>
		<pubDate>Sun, 25 Nov 2007 13:51:15 +0000</pubDate>
		<dc:creator>passion@php</dc:creator>
		
		<category><![CDATA[webservices]]></category>

		<guid isPermaLink="false">http://www.php-bloggersplace.org/2007/11/25/rest-xml-rpc-soap/</guid>
		<description><![CDATA[Introduction
Web services are Internet endpoints available most commonly through HTTP and HTTPS. The job of a web service is to consume HTTP requests. The messages have a specific schema applied to them, which in effect may be thought of as a transportable type system. Web services are also responsible for providing metadata describing the message [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p align="justify"><strong>Web services</strong> are Internet endpoints available most commonly through HTTP and HTTPS. The job of a web service is to consume HTTP requests. The messages have a specific schema applied to them, which in effect may be thought of as a transportable type system. Web services are also responsible for providing metadata describing the message both produced and consumed. The concept of web services can work, if and only if, the applications and servers follow a common language or protocols.  XML is the undisputed choice for this, but there are some architectural differences in implementation, which led to three main Web services standards which are <em>REST</em>, <em>XML-RPC</em>, and <em>SOAP</em>.</p>
<h3>REST</h3>
<p align="justify">The term was coined by Roy Fielding in his Ph.D. dissertation [1] to describe an architecture style of networked systems. <em>REST</em> is an acronym g for Representational State Transfer. The name itself explains the idea. Web is composed of resources and a client or an application basically tries to access these resources. The client application traverses the hyperlink to reach the required URL and ultimately the resource in returned to the client. This in effect changes the state of the client. In other words, the client application changes or transfers state with each resource representation.</p>
<p align="justify"><strong>REST</strong> was meant to describe the nature of the web. It is not a standard but uses the standards:</p>
<p>HTTP, URL ,XML/HTML/GIF/JPEG/etc (Resource Representations)and  text/xml, text/html, image/gif, image/jpeg, etc (MIME Types).</p>
<p align="justify">REST is in fact valuable for content-focused services. It works best when the resources are built as <strong>XML</strong> documents and the users can access it via HTTP Get. The entire system works on a tree of hyperlinks leading you to more details of the information, where the information is stored as <em>XML</em> documents. REST doesn’t have built-in support for complex types.</p>
<h3>XML-RPC</h3>
<p align="justify">While it seems obvious that the web is an excellent medium for distributing a user interface-oriented application, it may not seem so obvious that the same technology might be used to make method calls. One of the main reasons web services exist is different enterprises has agreed upon what a method call should look like and they all can access it over already existing <em>HTTP</em> connections. Web service method calls are encoded using XML. XML-RPC is the specification for making remote procedure calls over HTTP by using XML encoding. </p>
<p align="justify">REST was the specification used for simple XML data passing over HTTP, suitable for non-complex type data. In XML-RPC you call a specific function which is stored on the server or another machine and this function returns the data. Unlike REST this supports the PHP native types and other types like struct, date-time, base-64 binary data. It is similar SOAP but less complex.</h3>
<p align="justify">An <em>XML-RPC</em> server takes an input that consists of a simple XML encoding of a method call sent as an <strong>HTTP POST</strong>. An example is as follows:</p>
<p><code><br />
POST /xmlrpc-epi/xmlrpc-php-epi/sample/server.php HTTP/1.0<br />
User-Agent: xmlrpc-epi-php/0.2 (PHP)<br />
Host: localhost:80<br />
Content-Type: text/xml<br />
Content-Length: 191<br />
&lt;?xml version=’1.0’ encoding=’iso-8859-1’ ?><br />
&lt;methodCall><br />
&lt;methodName>greeting&lt;/methodName><br />
&lt;params><br />
&lt;param><br />
&lt;value><br />
&lt;string>World&lt;/string><br />
&lt;/value><br />
&lt;/param><br />
&lt;/params><br />
&lt;/methodCall><br />
</code></p>
<p align="justify">Assume that greeting() is a function that takes a string input and returns a string output consisting of the string “Hello, “ prepended to the input string. It returns a response that is formatted in a similar way. An example is the following:</p>
<p><code><br />
&lt;?xml version=’1.0’ encoding=’iso-8859-1’ ?><br />
&lt;methodResponse><br />
&lt;params><br />
&lt;param><br />
&lt;value><br />
&lt;array><br />
&lt;data><br />
&lt;value><br />
&lt;string>Hello, World&lt;/string><br />
&lt;/value><br />
&lt;/data><br />
&lt;/array><br />
&lt;/value><br />
&lt;/param><br />
&lt;/params><br />
&lt;/methodCall><br />
</code></p>
<h3>SOAP</h3>
<p align="justify">As mentioned before web method calls are encoded using XML. Another format that callers and services agree on is known as Simple Object Access Protocol (SOAP). The <em>SOAP</em> protocol is an <em>XML</em> formalization for message-based communication. <em>SOAP</em> defines how to format messages, how to bind messages over HTTP, and a standard error representation. Applications communicating using Remote Procedure Calls (RPC) between objects like <em>DCOM</em> and CORBA. But <em>HTTP</em> was not designed for this so  RPC represents a compatibility and security problem. Firewalls and proxy servers naturally tend to block this kind of traffic. So SOAP was developed to allow communication over HTTP, as it is supported by all browsers and servers. <em>SOAP</em> provides a way to communicate between applications running on different operating systems, with different technologies and programming languages.</p>
<p>A SOAP message is also an XML document which contains the following:</p>
<ol>
<li>An Envelope element to identify the document as SOAP message. </li>
<li>A Header element containing header information</li>
<li>A Body element containing call and response information.</li>
<li>A Fault element which gives information about error occurred during message processing. This is optional.</li>
</ol>
<p>The following code shows an SOAP example:</p>
<p><code><br />
POST /xmlrpc-epi/xmlrpc-php-epi/sample/server.php HTTP/1.0<br />
User-Agent: xmlrpc-epi-php/0.2 (PHP)<br />
Host: localhost:80<br />
Content-Type: text/xml<br />
Content-Length: 530<br />
&lt;?xml version=’1.0’ encoding=’’iso-8859-1’ ?><br />
&lt;SOAP-ENV:Envelope<br />
xmlns:SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/”<br />
xmlns:xsi=”http://www.w3.org/1999/XMLSchema-instance”<br />
xmlns:xsd=”http://www.w3.org/1999/XMLSchema”><br />
&lt;SOAP-ENV:Header><br />
...<br />
&lt;/SOAP-ENV:Header><br />
&lt;SOAP-ENV:Body><br />
&lt;greeting><br />
&lt;xsd:string>World&lt;/xsd:string><br />
&lt;/greeting><br />
&lt;/SOAP-ENV:Body><br />
&lt;/SOAP-ENV:Envelope><br />
</code></p>
<p>The response may be something like the following:</p>
<p><code><br />
&lt;?xml version=’1.0’ encoding=’iso-8859-1’ ?><br />
&lt;SOAP-ENV:Envelope<br />
xmlns:SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/”<br />
xmlns:xsi=”http://www.w3.org/1999/XMLSchema-instance”<br />
xmlns:xsd=”http://www.w3.org/1999/XMLSchema”><br />
&lt;SOAP-ENV:Header><br />
...<br />
&lt;/SOAP-ENV:Header><br />
&lt;SOAP-ENV:Body><br />
&lt;greetingResponse><br />
&lt;SOAP-ENC:Array SOAP-ENC:arrayType=”xsd:string[1]”><br />
&lt;xsd:string>Hello, World</xsd:string><br />
&lt;/SOAP-ENC:Array><br />
&lt;/greetingResponse><br />
&lt;/SOAP-ENV:Body><br />
&lt;/SOAP-ENV:Envelope><br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-bloggersplace.org/2007/11/25/rest-xml-rpc-soap/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The SimpleXML API</title>
		<link>http://www.php-bloggersplace.org/2007/11/15/the-simplexml-api/</link>
		<comments>http://www.php-bloggersplace.org/2007/11/15/the-simplexml-api/#comments</comments>
		<pubDate>Thu, 15 Nov 2007 18:52:34 +0000</pubDate>
		<dc:creator>passion@php</dc:creator>
		
		<category><![CDATA[PHP Basics]]></category>

		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.php-bloggersplace.org/2007/11/15/the-simplexml-api/</guid>
		<description><![CDATA[Introduction
SimpleXML API is new in PHP 5. It is basically an XML parser i.e. if you know an XML document’s layout, you can access the elements, attributes and the text data using SimpleXML  parser’s in-built functionalities. 
PHP XML Parsers
There are two types of XML Parsers. 


The Tree-based Parser:  this type of parsers converts [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p align="justify">SimpleXML API is new in PHP 5. It is basically an XML parser i.e. if you know an XML document’s layout, you can access the elements, attributes and the text data using SimpleXML  parser’s in-built functionalities. </p>
<h3>PHP XML Parsers</h3>
<p>There are two types of XML Parsers. </p>
<ol>
<li>
<p align="justify">The Tree-based Parser:  this type of parsers converts an XML document to a tree-based structure called ‘Document Object Model’ (DOM). This way it can analyse the entire document and provides different methods to access all the elements, attributes and text data. Example of this type of parser is DOM XML parser, which is part of core PHP.</p>
</li>
<li>
<p align="justify">The Event-based Parser: this kind of parser considers and XML document as a series of events. So when an event occurs (like a node is encountered) the parser calls a specific event handler to handle it. Example of this type of parser is the Expat parser of core PHP.</p>
</li>
</ol>
<h3>What is SimpleXML API and how it works</h3>
<p align="justify">SimpleXML  API is another XML parser in PHP. It is part of PHP 5. It also works like DOM XML parser but instead of holding the entire document as a DOM object it stores the document’s elements as native PHP variables. So this parser is faster and easy to use. As it need not traverse the entire tree structure for every job. Most of the job requires an iterative job being done on some particular node. It dispenses with web standard with better flexibility, simplicity and better memory usage.</p>
<p align="justify">SimpleXML transforms the XML document into a SimpleXMLElement object. All the elements in the document are converted to this object’s attributes. If there is more than one level of elements those are stored into an array. Attributes of each is stored into an associative array, where attribute name corresponds to index. Text data of the element are converted to strings.</p>
<h3>Using SimpleXML</h3>
<p align="justify">SimpleXML is fast and flexible, it is used to read  XML files, to extract data from XML strings and for editing text nodes or attributes.</p>
<p align="justify">The following functions are used to load an XML document, create the SimpleXMLElement object and manipulate it in various ways using the related arrays.</p>
<table>
<tr>
<td>Function</td>
<td>Description</td>
</tr>
<tr>
<td>addAttribute()</td>
<td>Adds an attribute to the SimpleXML element</td>
</tr>
<tr>
<td>addChild()</td>
<td>Adds a child element the SimpleXML element</td>
</tr>
<tr>
<td>asXML()</td>
<td>Gets an XML string from a SimpleXML element</td>
</tr>
<tr>
<td>attributes()</td>
<td>Gets a SimpleXML element&#8217;s attributes</td>
</tr>
<tr>
<td>children()</td>
<td>Gets the children of a specified node</td>
</tr>
<tr>
<td>getDocNamespaces()</td>
<td>Gets the namespaces of an XML document</td>
</tr>
<tr>
<td>getName()</td>
<td>Gets the name of a SimpleXML element</td>
</tr>
<tr>
<td>getNamespaces()</td>
<td>Gets the namespaces from XML data</td>
</tr>
<tr>
<td>registerXPathNamespace()</td>
<td>Creates a namespace context for the next XPath query</td>
</tr>
<tr>
<td>simplexml_import_dom()</td>
<td>Gets a SimpleXMLElement object from a DOM node</td>
</tr>
<tr>
<td>simplexml_load_file()</td>
<td>Gets a SimpleXMLElement object from an XML document</td>
</tr>
<tr>
<td>simplexml_load_string()</td>
<td>Gets a SimpleXMLElement object from an XML string</td>
</tr>
<tr>
<td>Xpath()</td>
<td>Runs an XPath query on XML data</td>
</tr>
</table>
<p align="justify">The following code shows the how the SimpleXML API can be used to get variable values out of an XML file with just a few lines of code.</p>
<p><code>&lt;?php<br />
$recipe = simplexml_load_file(“recipe.xml”);<br />
$ingredients = $recipe->ingredients;<br />
$directions = $recipe->directions;<br />
$servings = $recipe->servings;<br />
foreach ($ingredients as $ingredient)<br />
{<br />
print “&lt;P>Ingredient: $ingredient”;<br />
}<br />
print “&lt;P>Directions: $directions”;<br />
print “&lt;P>Serves $servings”;<br />
?><br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-bloggersplace.org/2007/11/15/the-simplexml-api/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Loop Constructs in PHP</title>
		<link>http://www.php-bloggersplace.org/2007/11/10/using-loop-constructs-in-php/</link>
		<comments>http://www.php-bloggersplace.org/2007/11/10/using-loop-constructs-in-php/#comments</comments>
		<pubDate>Sat, 10 Nov 2007 17:21:10 +0000</pubDate>
		<dc:creator>passion@php</dc:creator>
		
		<category><![CDATA[PHP Basics]]></category>

		<category><![CDATA[loops]]></category>

		<guid isPermaLink="false">http://www.php-bloggersplace.org/2007/11/10/using-loop-constructs-in-php/</guid>
		<description><![CDATA[Introduction
Loop structures are used to execute one or more lines of code repetitively. The following loop constructs are supported by PHP.

The while loop
The do&#8230;.while loop
The for loop



The while Loop
The while loop construct is used to execute a block of statements for a definite number of times, depending on a condition. The while statement always checks [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p align="justify">Loop structures are used to execute one or more lines of code repetitively. The following loop constructs are supported by PHP.</p>
<ol>
<li>The while loop</li>
<li>The do&#8230;.while loop</li>
<li>The for loop</li>
</ol>
<ol>
<li>
<h3>The while Loop</h3>
<p align="justify">The while loop construct is used to execute a block of statements for a definite number of times, depending on a condition. The while statement always checks the condition before executing the statements within the loop. When the execution reaches the last statement in the while loop, the control is passed back to the beginning of the loop. If the condition still holds true, the statements within the loop are executed again. The execution of the statements within the loop continues until the condition evaluates to false.</p>
<p>The following code is the syntax of the while loop construct:</p>
<p><code><br />
while (expression)<br />
{<br />
	statements;<br />
}<br />
</code><br />
The following code is an example of the while loop construct:<br />
<code><br />
while (FALSE)<br />
print(“This will never print.&lt;BR>”);<br />
If you want to run an infinite loop:<br />
while (TRUE)<br />
print(“All work and no play makes Jack a dull boy.&lt;BR>”);<br />
To print a line 10 times:<br />
$count = 1;<br />
while ($count <= 10)<br />
{<br />
print(“count is $count&lt;BR>”);<br />
$count = $count + 1;<br />
}<br />
</code></p>
<p align="justify">The preceding code creates an integer variable count and stores 1 into it. Next part of the code checks whether count is reaching 10 and till so it prints the line stating the value of count. Once the value of count is 10 the loop terminates.</p>
</li>
<li>
<h3>The do&#8230;while Loop</h3>
<p align="justify">The do&#8230;while loop construct is similar to the while loop construct. Both iterate until the specified loop condition becomes false. However, in the do&#8230;while loop, the body of the loop is executed at least once and the condition is evaluated for subsequent iterations.</p>
<p>The following code is the syntax of the do&#8230;while loop construct:<br />
<code><br />
do<br />
{<br />
statements;<br />
}while(expression)<br />
The following code snippet explains the do...while loop:<br />
$count = 45;<br />
do{<br />
print(“count is $count&lt;BR>”);<br />
$count = $count + 1;<br />
}while ($count <= 10)<br />
</code></p>
<p>It prints the single line:</p>
<p>count is 45
</li>
<li>
<h3>The for Loop</h3>
<p align="justify">The for loop structure is used to execute a block of statements for a specific number of times. The following code is the syntax of the for loop construct:</p>
<p><code><br />
for(initialization;  termination;  increment/decrement)<br />
{<br />
statements;<br />
}<br />
</code></p>
<p align="justify">The initialization expression initializes the for loop construct. It is executed once at the beginning of the loop. The termination expression determines when to terminate the loop. At the beginning of the loop, this expression is evaluated for each iteration. When the expression evaluates to false, the loop terminates. Then, through the loop, the increment or decrement expression gets invoked after each iteration. All these components are optional.<br />
You can create an infinite loop by omitting all the three expressions, like:</p>
<p><code><br />
for( ; ; )<br />
{<br />
	....<br />
}<br />
</code></p>
<p>The following code snippet explains for construct:<br />
<code><br />
for ($x = 1, $y = 1, $z = 1; //initial expressions<br />
$y < 10, $z < 10; // termination checks<br />
$x = $x + 1, $y = $y + 2, // loop-end expressions<br />
$z = $z + 3)<br />
print(“$x, $y, $z<BR>”);<br />
</code></p>
<p>would give the browser output:<br />
1, 1, 1<br />
2, 3, 4<br />
3, 5, 7
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.php-bloggersplace.org/2007/11/10/using-loop-constructs-in-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Register Global Variables</title>
		<link>http://www.php-bloggersplace.org/2007/11/06/register-global-variables/</link>
		<comments>http://www.php-bloggersplace.org/2007/11/06/register-global-variables/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 17:49:09 +0000</pubDate>
		<dc:creator>passion@php</dc:creator>
		
		<category><![CDATA[PHP Basics]]></category>

		<guid isPermaLink="false">http://www.php-bloggersplace.org/2007/11/06/register-global-variables/</guid>
		<description><![CDATA[Introduction
Register_globals is a PHP directive. It’s value could be set on or off in PHP.ini file. When a user submits some variables to a PHP script for example, by posting a form, data from cookies or URL-encoded data etc., these variables are considered as global variables if the ‘register_globals’ directive is set as ‘on’. In [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p align="justify">Register_globals is a PHP directive. It’s value could be set on or off in PHP.ini file. When a user submits some variables to a PHP script for example, by posting a form, data from cookies or URL-encoded data etc., these variables are considered as global variables if the ‘register_globals’ directive is set as ‘on’. In such case the value of the variables are available to all the scripta and consequently could be tampered. This gives a security problem. On the other hand, if it is ‘off’(it is ‘off’ by default from PHP 4.2.0), you have to contact your host while upgrading your site. But the best practice is, as we are going to see, to use the predefined variables like $_ENV, $_GET, $_POST, $_COOKIE, or $_SERVER instead of using the more general  $_REQUEST and initialise the important user-defined variables first.</p>
<h3>Using Register Globals</h3>
<p align="justify">As mentioned earlier form PHP 4.2.0 onwards register_globals directive is by default set to ‘off’. Previously it was ‘on’ by default and led to insecure coding practice. When set to ‘on’ it makes the Environment, GET, POST, Cookie and Server variables  registered as global variables and allows the user to inject variables and values into the program.<br />
The following examples explain the concept:</p>
<ol>
<li>
<p align="justify">Let us assume when our user with password ‘12345’ posts a form the control passes to the following code name test.php. Our user does not know the password but want the administrative privileges. The test.php is as follows</p>
<p><code>&lt;?php<br />
if (isset($_POST["password"]) &#038;&#038; $_POST["password"] == "12345") {<br />
    $admin = TRUE;<br />
}<br />
?><br />
</code></p>
<p align="justify">Now by appending ?admin=1 to the URL of the page the user can set the value of admin to true. This is called injection. So when, register_globals is set to on user is able to inject variables into the program. In the above example, he/she can create a variable admin and set it’s value to 1.</p>
</li>
<li>
<p align="justify">In this example the user can set the value of the variable authorized to true by injection. The code is explanatory.</p>
<p><code>&lt;?php<br />
// define $authorized = true only if user is authenticated<br />
if (authenticated_user()) {<br />
    $authorized = true;<br />
}<br />
// Because we didn't first initialize $authorized as false, this might be<br />
// defined through register_globals, like from GET auth.php?authorized=1<br />
// So, anyone can be seen as authenticated!<br />
if ($authorized) {<br />
    include "/highly/sensitive/data.php";<br />
}<br />
?>
</p>
</li>
</ol>
<h3>Best practice</h3>
<ol>
<li>
<p align="justify">Setting up a .htaccess file : you can create a .htaccess file in the main directory of your site that has the PHP script and write the following code in that file.</p>
<p>   php_flag register_globals on</p>
<p>You can set it to ‘off’ for testing your site.
</li>
<li>
<p align="justify">It is always recommended that  register_globals is set to Off in your php.ini. but it considered better coding practice to  always initialize your variables. We can change our previous example to:</p>
<p><code>&lt;?php<br />
$admin = FALSE;<br />
if (isset($_POST["password"]) &#038;&#038; $_POST["password"] == "12345") {<br />
    $admin = TRUE;<br />
}<br />
?><br />
</code>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.php-bloggersplace.org/2007/11/06/register-global-variables/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Rand () PHP Function</title>
		<link>http://www.php-bloggersplace.org/2007/10/27/rand-php-function/</link>
		<comments>http://www.php-bloggersplace.org/2007/10/27/rand-php-function/#comments</comments>
		<pubDate>Sat, 27 Oct 2007 18:18:59 +0000</pubDate>
		<dc:creator>passion@php</dc:creator>
		
		<category><![CDATA[PHP Basics]]></category>

		<guid isPermaLink="false">http://www.php-bloggersplace.org/2007/10/27/rand-php-function/</guid>
		<description><![CDATA[The rand() function is used to generate a random number in PHP. It can also be used to generate a random number within a specific range (for example a number between 10 and 30.) On some platforms, Windows for example, if unspecified the largest number that will be generated is 32768, however you can set [...]]]></description>
			<content:encoded><![CDATA[<p align=”justify”>The <strong>rand()</strong> function is used to generate a random number in PHP. It can also be used to generate a random number within a specific range (for example a number between 10 and 30.) On some platforms, Windows for example, if unspecified the largest number that will be generated is 32768, however you can set a specific range to include higher numbers.</p>
<p>Examples: </p>
<p><code>&lt;?php<br />
print rand() . "&lt;br>";<br />
//generates and prints a random number<br />
print rand(10, 30);<br />
//generates and prints a random number between 10 and 30 (10 and 30 ARE included)<br />
print rand(1, 1000000);<br />
//generates and prints a random number between on and one million<br />
?><br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-bloggersplace.org/2007/10/27/rand-php-function/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
