<?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>PHP Resource - PHP Script Tutorial, Forum, Help, and Discussion</title>
	<atom:link href="http://www.phpscriptschool.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phpscriptschool.com</link>
	<description>PHP developers blog</description>
	<lastBuildDate>Mon, 14 Mar 2011 11:38:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Increasing demand of web development solutions for today’s businesses</title>
		<link>http://www.phpscriptschool.com/increasing-demand-of-web-development-solutions-for-todays-businesses</link>
		<comments>http://www.phpscriptschool.com/increasing-demand-of-web-development-solutions-for-todays-businesses#comments</comments>
		<pubDate>Mon, 14 Mar 2011 11:36:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.phpscriptschool.com/?p=24</guid>
		<description><![CDATA[Today is the technological age. Every sector and business industry needs to rely on the technology for upgrading and standing firm in the competitive world. Web designing and web development is not different from this. Lots and lots of changes are taking place in the industry and business people need to keep themselves updated to [...]]]></description>
			<content:encoded><![CDATA[<p>Today is the technological age. Every sector and business industry needs to rely on the technology for upgrading and standing firm in the competitive world. Web designing and web development is not different from this. Lots and lots of changes are taking place in the industry and business people need to keep themselves updated to stand firm in the business.</p>
<p>Innovative ideas and new tools are required to get success. Old age talent is shifting towards the latest technology and beating the man power. Web solutions is in demand all where. Look at any sector, you will find the expansion and use of web development services that make them run their business smoothly. Internet banking, e commerce, online hotel booking, online ticket booking, etc. are all possible through the latest technology and web development.</p>
<p>With the growing need of IT services and web solutions there is increasing need of web development companies seen throughout the world. Businesses all over the world need top web development solutions for growing their business and to reach out internationally. If you are aiming for the fast online success and need web development services you should look for the software professionals who can help customize the services according to your requirements.</p>
<p>Effective <strong><a title="web developers" href="http://www.iflexion.com">web developers</a></strong> and talents know the trends of market and understand the market conditions. They aim high at providing the best possible services at best possible rates that can not only welfare them but their clients also. The ideal business people in the field employ better technology, tools and strategy to provide the satisfactory services.</p>
<p>Web development include various things like creative web designing, web redesigning, technical designing, etc. But the main part of the business involves making the website beautiful, attractive and appealing at first sight.<br />
There are lots more that come in the category of development and designing.</p>
<p>These are:<br />
•    Animations,<br />
•    website design,<br />
•    and flash design<br />
•    custom programming,<br />
•    photo website development,<br />
•    ERP,<br />
•    content management system (CMS)<br />
•    internet marketing,<br />
•    blog management,<br />
•    search engine promotions<br />
•    and much more</p>
<p>Website <strong><a title="php development" href="http://www.iflexion.com/capabilities/php_mysql_development.php">php development</a></strong> services are essential and most beneficial for the business of today to grow effectively in no time. it is therefore important that you choose the best company for your business by researching and comparing some of the top ones. The best web development can help you in increasing your credibility and reputation online which further is very effective in enhancing your overall business profits.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpscriptschool.com/increasing-demand-of-web-development-solutions-for-todays-businesses/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introductory PHP For Non-Programmers</title>
		<link>http://www.phpscriptschool.com/introductory-php-for-non-programmers</link>
		<comments>http://www.phpscriptschool.com/introductory-php-for-non-programmers#comments</comments>
		<pubDate>Thu, 30 Dec 2010 13:03:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.phpscriptschool.com/?p=5</guid>
		<description><![CDATA[PHP can be used for a lot of different things, and is one of the most powerful scripting languages available on the web. Not to mention it&#8217;s extremely cheap and widely used. However, one thing that PHP is lacking, and in fact most scripting languages are, is a way to update pages in real-time, without [...]]]></description>
			<content:encoded><![CDATA[<p>PHP can be used for a lot of different things, and is one of the most powerful scripting languages available on the web. Not to mention it&#8217;s extremely cheap and widely used. However, one thing that PHP is lacking, and in fact most scripting languages are, is a way to update pages in real-time, without having to reload a page or submit a form.</p>
<p>The internet wasn&#8217;t made for this. The web browser closes the connection with the web server as soon as it has received all the data. This means that after this no more data can be exchanged. What if you want to do an update though? If you&#8217;re building a PHP application (e.g. a high-quality content management system), then it&#8217;d be ideal if it worked almost like a native Windows/Linux application.</p>
<p>But that requires real-time updates. Something that isn&#8217;t possible, or so you would think. A good example of an application that works in (almost) real-time is Google&#8217;s GMail (http://gmail.google.com). Everything is JavaScript powered, and it&#8217;s very powerful and dynamic. In fact, this is one of the biggest selling-points of GMail. What if you could have this in your own PHP websites as well? Guess what, I&#8217;m going to show you in this article.</p>
<p>How does it work?</p>
<p>If you want to execute a PHP script, you need to reload a page, submit a form, or something similar. Basically, a new connection to the server needs to be opened, and this means that the browser goes to a new page, losing the previous page. For a long while now, web developers have been using tricks to get around this, like using a 1&#215;1 iframe, where a new PHP page is loaded, but this is far from ideal.</p>
<p>Now, there is a new way of executing a PHP script without having to reload the page. The basis behind this new way is a JavaScript component called the XML HTTP Request Object. See http://jibbering.com/2002/4/httprequest.html for more information about the component. It is supported in all major browsers (Internet Explorer 5.5+, Safari, Mozilla/Firefox and Opera 7.6+).</p>
<p>PHP is a server-side scripting language for creating dynamic Web pages. You create pages with PHP and HTML. When a visitor opens the page, the server processes the PHP commands and then sends the results to the visitor&#8217;s browser, just as with ASP or ColdFusion. Unlike ASP or ColdFusion, however, PHP is Open Source and cross-platform. PHP runs on Windows NT and many Unix versions, and it can be built as an Apache module and as a binary that can run as a CGI. When built as an Apache module, PHP is especially lightweight and speedy. Without any process creation overhead, it can return results quickly, but it doesn&#8217;t require the tuning of mod_perl to keep your server&#8217;s memory image small.</p>
<p>In addition to manipulating the content of your pages, PHP can also send HTTP headers. You can set cookies, manage authentication, and redirect users. It offers excellent connectivity to many databases (and ODBC), and integration with various external libraries that let you do everything from generating PDF documents to parsing XML.</p>
<p>PHP goes right into your Web pages, so there&#8217;s no need for a special development environment or IDE. You start a block of PHP code with . (You can also configure PHP to use ASP-style &lt;% %&gt; tags or even .) The PHP engine processes everything between those tags.</p>
<p>PHP&#8217;s language syntax is similar to C&#8217;s and Perl&#8217;s. You don&#8217;t have to declare variables before you use them, and it&#8217;s easy to create arrays and hashes (associative arrays). PHP even has some rudimentary object-oriented features, providing a helpful way to organize and encapsulate your code.</p>
<p>Although PHP runs fastest embedded in Apache, there are instructions on the PHP Web site for seamless setup with Microsoft IIS and Netscape Enterprise Server. If you don&#8217;t already have a copy of PHP, you can download it at the official Web site. You&#8217;ll also find a manual that documents all of PHP&#8217;s functions and features.</p>
<p>When you started reading this sentence you assumed lo acabaría en inglés. However, I didn&#8217;t finish in English. This begs the question, &#8216;In which language did I finish?&#8217; Unless I tell you the language, you&#8217;d have to run around and compare the words against known words in order to learn that it was Spanish, but I&#8217;d bet you&#8217;d give up and move on first. Servers work much the same way; if you don&#8217;t let it know the language it assumes you&#8217;re speaking to someone else (the browser) and sends it along. Servers aren&#8217;t even friendly enough to give it a whack and see how it comes out.</p>
<p>So, what&#8217;s server-speak for &#8220;Here comes PHP!&#8221;? Well, it definitely looks foreign:</p>
<p>And, to say &#8220;OK, back to browser-speak.&#8221;, try</p>
<p>?&gt;</p>
<p>Sure. Whatever. It&#8217;s no use telling the server you&#8217;re speaking PHP because you only know how to say &#8220;I speak PHP&#8221;. What&#8217;s that going to do for you? Well, imagine you were visiting a scripts site and wondering how you could put today&#8217;s date on your webpage when you come across the following little snippet:</p>
<p>To display the date on your webpage, find the area you want to put the date then insert the code below.</p>
<p><strong>echo date(&#8216;m/d/Y&#8217;);<br />
</strong></p>
<p><strong><br />
</strong></p>
<p>Now, you&#8217;re equipped with 2 statements: &#8220;I&#8217;m going to be speaking PHP&#8221; and &#8220;Today&#8217;s date is mm/dd/YYYY&#8221;. You then edit the file you want to put the date in by inserting this code in the desired location:</p>
<p>Put the file back on the server and you&#8217;re date shows up exactly as the snippet said it would. Or does it?</p>
<p>If you got lucky, it showed up. If not, there&#8217;s a little more to learn. There&#8217;s actually more than one way to tell the server that PHP is coming and I&#8217;ve only covered one way &#8211; the other ways aren&#8217;t necessary for you to know in order to use PHP on your site. Most servers require a bit more information first &#8211; they want the name of the file to say whether PHP is there or not. To tell the server that PHP is inside the file, you need to change the extension (the part after the dot) to php. Uh, sure, the extension. Does this guy speak English? YEP! lol. If that wasn&#8217;t clear, let&#8217;s illustrate by assuming your file was called index.html when you downloaded it to edit. Before you upload that file back to the server, you need to change &#8220;html&#8221; to &#8220;php&#8221;, so that the file is called index.php. Without that change most servers won&#8217;t even look for PHP. The nice thing is that even if a file ends in &#8220;php&#8221;, the server still looks for those opening pieces saying &#8220;Here comes PHP!&#8221; before trying to read what follows in PHP and just sends everything back to the browser which is outside of PHP, so you don&#8217;t hurt anything!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpscriptschool.com/introductory-php-for-non-programmers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic Tutorial</title>
		<link>http://www.phpscriptschool.com/basic-tutorial</link>
		<comments>http://www.phpscriptschool.com/basic-tutorial#comments</comments>
		<pubDate>Fri, 17 Dec 2010 13:10:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.phpscriptschool.com/?p=8</guid>
		<description><![CDATA[Basic Tutorial Tutorial Object What PHP is, what a PHP file is, how PHP works, and what PHP can do for you. What you need to get PHP up and running! Basic PHP syntax. Filter  Order Date asc Date desc Title asc Title desc Hits asc Hits desc Ordering Display # 5 10 15 20 [...]]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tbody>
<tr>
<td colspan="2" width="100%">Basic Tutorial</td>
</tr>
<tr>
<td colspan="2" width="60%" valign="top">Tutorial Object</p>
<ul>
<li>What PHP is, what a PHP file is, how PHP works, and what PHP can do for you.</li>
<li>What you need to get PHP up and running!</li>
<li>Basic PHP syntax.</li>
</ul>
</td>
</tr>
<tr>
<td>
<form method="post">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td colspan="4">
<table>
<tbody>
<tr>
<td width="100%" align="right">Filter <br />
<input name="filter" type="text" /></td>
<td width="100%" align="right">Order</p>
<select name="order" size="1">
<option value="date">Date asc</option>
<option value="rdate">Date desc</option>
<option selected="selected" value="alpha">Title asc</option>
<option value="ralpha">Title desc</option>
<option value="hits">Hits asc</option>
<option value="rhits">Hits desc</option>
<option value="order">Ordering</option>
</select>
</td>
<td width="100%" align="right">Display #</p>
<select name="limit" size="1">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
<option selected="selected" value="50">50</option>
</select>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td width="45%">Item Title</td>
<td width="5%" align="right">Hits</td>
</tr>
<tr>
<td><a> A Short Intro to GD </a></td>
<td align="center">87</td>
</tr>
<tr>
<td><a> Page Titles by Folder Names </a></td>
<td align="center">47</td>
</tr>
<tr>
<td><a> Part 1.Introduction </a></td>
<td align="center">122</td>
</tr>
<tr>
<td><a> Part 2.Your first PHP-enabled page </a></td>
<td align="center">90</td>
</tr>
<tr>
<td><a> Part 3.Something Useful </a></td>
<td align="center">83</td>
</tr>
<tr>
<td><a> Part 4.Dealing with Forms </a></td>
<td align="center">79</td>
</tr>
<tr>
<td><a> Part 5.Using old code with new versions of PHP </a></td>
<td align="center">67</td>
</tr>
<tr>
<td><a> Part 6.What&#8217;s next? </a></td>
<td align="center">52</td>
</tr>
<tr>
<td><a> PHP Includes </a></td>
<td align="center">15</td>
</tr>
<tr>
<td><a> Simple Solution for Php Includes &#8211; IFrames </a></td>
<td align="center">29</td>
</tr>
<tr>
<td colspan="4"></td>
</tr>
<tr>
<td colspan="4" align="center">&lt;&lt; Start &lt; Prev 1 Next &gt; End &gt;&gt;</td>
</tr>
<tr>
<td colspan="4" align="right">Results 1 &#8211; 10 of 10</td>
</tr>
</tbody>
</table>
</form>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.phpscriptschool.com/basic-tutorial/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple XML Parsing</title>
		<link>http://www.phpscriptschool.com/simple-xml-parsing</link>
		<comments>http://www.phpscriptschool.com/simple-xml-parsing#comments</comments>
		<pubDate>Wed, 15 Dec 2010 13:13:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.phpscriptschool.com/?p=10</guid>
		<description><![CDATA[Now, I may not be a pro at this XML parsing thing, nor at making the XML files themselves, but I do know that XML can be a really, really cool thing if used correctly. I&#8217;ve been working the past few months on a website that uses XML to communicate between client and server to [...]]]></description>
			<content:encoded><![CDATA[<p>Now, I may not be a pro at this XML parsing thing, nor at  making the XML files themselves, but I do know that XML can be a really, really  cool thing if used correctly. I&#8217;ve been working the past few months on a website  that uses XML to communicate between client and server to grab information off  of eBay. It&#8217;s a pretty nice little API system that lets you get all sorts of  information about auctions and the like.</p>
<p>Now, I&#8217;m not going to get that  detailed on this, I just want to give you a basic introduction to it all and get  the ball rolling. Now, as always, I&#8217;m sure that this may not be the best way to  parse data like this, but it sure does make it a lot easier for me to use the  information out of an XML document.</p>
<p>First off, I&#8217;ll give you some sample  XML:<br />
&lt;result&gt;<br />
&lt;username&gt;testing&lt;/username&gt;<br />
&lt;password&gt;foobarbaz&lt;/password&gt;<br />
&lt;name&gt;enygma&lt;/name&gt;<br />
&lt;/result&gt;</p>
<p>Now,  I know that&#8217;s not strictly &#8220;correctly formatted XML&#8221; but you get the idea. There  it&#8217;s a hierarchical relationship in the tags &#8211; for each opening tag, there needs  to be a closing tag, and inside of those, there can contain information.  Usually, people pick good tag names that describe the information inside them.  My example might be what you get back if you request something from a server  (user information, for example). The &#8220;result&#8221; would contain the username,  password and their name. Now, we get to the fun part &#8211; the  parsing&#8230;.</p>
<p>First off, you need to understand that the XML functions in  PHP need to have four parts &#8211; the function to parse the opening tag, the  function to parse the closing tag, the function to parse the &#8220;guts&#8221; of the tags  (the information inside them), and the initial function that ties them all  together. This last one is not completely necessary, but sure makes it nice to  just pass it some XML and have it return the results.</p>
<p>In this example,  I&#8217;m going to have the XML parser return the values in an array formatted  like:</p>
<p>&#8220;username&#8221;=&gt;testing<br />
&#8220;password&#8221;=&gt;foobarbaz<br />
&#8220;name&#8221;=&gt;enygma</p>
<p>This,  as I&#8217;ve found out, is one of the more useful ways to use the information once  you have it. The function can pass back the array of information<br />
and you can  then use it as you see fit. Now, there are going to be times when this just isnt  enough &#8211; but those times are for another tutorial.<br />
Anyway, on with the  code!</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
&lt;?<br />
$info=&#8221;&lt;result&gt;&lt;username&gt;testing&lt;/username&gt;&lt;password&gt;foobarbaz&lt;/password&gt;&lt;name&gt;enygma&lt;/name&gt;&lt;/result&gt;&#8221;;<br />
class  parse{<br />
function startElement($parser, $name, $attrs){<br />
global  $currentTag;<br />
$currentTag=$name;<br />
}</p>
<p>function endElement($parser,  $tag){<br />
global $currentTag;<br />
$currentTag=&#8221;";<br />
}</p>
<p>function  getInfo($parser, $data){<br />
global  $currentTag;<br />
$this-&gt;info_array[$currentTag]=$data;<br />
}</p>
<p>function  parseXML($data){<br />
// make the parser to get the XML<br />
$xml_parser =  xml_parser_create();<br />
xml_set_object($xml_parser,  &amp;$this);<br />
xml_set_element_handler($xml_parser, &#8220;startElement&#8221;,  &#8220;endElement&#8221;);<br />
xml_set_character_data_handler($xml_parser,  &#8220;getInfo&#8221;);<br />
xml_parse($xml_parser,  $data);<br />
xml_parser_free($xml_parser);</p>
<p>print_r($this-&gt;info_array);<br />
}<br />
}</p>
<p>$parse=new  parse;<br />
$parse-&gt;parseXML($info);<br />
?&gt;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>I  used a class here just so that it&#8217;s easier to keep the XML paring to itself.  This way, you can just include the file, call $parse-&gt;parseXML($info) like I  do at the bottom, and get the results back. In this example, I take the XML that  I gave you up at the top, and pass it through the needed functions to give me a  nice array of the infomation as the output.</p>
<p>Let&#8217;s step through this so  that we can see what these things do. First off, we have the &#8220;base function&#8221;  called parseXML. This is where all the fun gets going. The XML stream (in this  case, $info) is passed in as $data to the function. We then create the XML  parser object with the xml_parser_create() function. This makes the object so  that we can use it ($xml_parser). Now, the next function, xml_set_object, lets  us use this object in the &#8220;parse&#8221; class. Otherwise, it would get confused and  not understand that we want to use it inside the class and probably just freak  out.</p>
<p>The xml_set_element_handler function is one of the cooler functions  in the parser. It helps us define what function names we want to use for the  initial element handler (opening tag) and the ending element handler (close  tag). This allows us to make custom fucntions that do certain things based on  which end of the XML tag we are on. You can name your two functions anything  that you want, just so long as you change the second and third values in this  function to match the function names. Those two functions do have very specific  variables that they need to be passed, so you always have to define them like  this:</p>
<p>function startElement($parser, $name, $attrs)<br />
function  endElement($parser, $tag)</p>
<p>If you don&#8217;t, not only with PHP complain about  it, but it just flat out won&#8217;t work.</p>
<p>The xml_set_character_data_handler  function is where the real meat of it all is, though. This is where you tell the  XML parser what function to use for the data inside the XML tags. You can do all  sorts of things with this one &#8211; but we chose to just add the current tag and  it&#8217;s value to an array (made global in the class though the $this-&gt; before  it).</p>
<p>Almost done &#8211; stick with me! The xml_parse function takes in the  $data that we passed to the function and ships it off to the parser ($xml_parse)  to get taken care of. It then goes through the tags, calling startElement,  getInfo, and endElement (in that order) for each tag. In our example, it adds  the $currentTag (a global value) to the array with whatever value is inside that  tag. The final function (xml_parser_free) is just mainly a good idea. It frees  up the memory that the parser was using and &#8220;cleans up&#8221; the things we&#8217;ve  done.</p>
<p>Well, I do hope that this has been a help to you in your  XML-parsing needs. If you have any further questions, there are lots of other  tutorials about that probably get more into specifics than this one did. And, as  always, you&#8217;re more than welcome to email me at enygma@phpdeveloper.org.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpscriptschool.com/simple-xml-parsing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP On-The-Fly!</title>
		<link>http://www.phpscriptschool.com/php-on-the-fly</link>
		<comments>http://www.phpscriptschool.com/php-on-the-fly#comments</comments>
		<pubDate>Thu, 02 Dec 2010 13:21:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.phpscriptschool.com/?p=20</guid>
		<description><![CDATA[Introduction PHP can be used for a lot of different things, and is one of the most powerful scripting languages available on the web. Not to mention it&#8217;s extremely cheap and widely used. However, one thing that PHP is lacking, and in fact most scripting languages are, is a way to update pages in real-time, [...]]]></description>
			<content:encoded><![CDATA[<p>Introduction</p>
<p>PHP can be used for a lot of different things, and is one of the most  powerful scripting languages available on the web. Not to mention it&#8217;s extremely  cheap and widely used. However, one thing that PHP is lacking, and in fact most  scripting languages are, is a way to update pages in real-time, without having  to reload a page or submit a form.</p>
<p>The internet wasn&#8217;t made for this. The web browser closes the connection with  the web server as soon as it has received all the data. This means that after  this no more data can be exchanged. What if you want to do an update though? If  you&#8217;re building a PHP application (e.g. a high-quality content management  system), then it&#8217;d be ideal if it worked almost like a native Windows/Linux  application.</p>
<p>But that requires real-time updates. Something that isn&#8217;t possible, or so you  would think. A good example of an application that works in (almost) real-time  is Google&#8217;s GMail (http://gmail.google.com). Everything is JavaScript powered, and  it&#8217;s very powerful and dynamic. In fact, this is one of the biggest  selling-points of GMail. What if you could have this in your own PHP websites as  well? Guess what, I&#8217;m going to show you in this article.</p>
<p>How does it work?</p>
<p>If you want to execute a PHP script, you need to reload a page, submit a  form, or something similar. Basically, a new connection to the server needs to  be opened, and this means that the browser goes to a new page, losing the  previous page. For a long while now, web developers have been using tricks to  get around this, like using a 1&#215;1 iframe, where a new PHP page is loaded, but  this is far from ideal.</p>
<p>Now, there is a new way of executing a PHP script without having to reload  the page. The basis behind this new way is a JavaScript component called the XML  HTTP Request Object. See http://jibbering.com/2002/4/httprequest.html for more information  about the component. It is supported in all major browsers (Internet Explorer  5.5+, Safari, Mozilla/Firefox and Opera 7.6+).</p>
<p>With this object and some custom JavaScript functions, you can create some  rather impressive PHP applications. Let&#8217;s look at a first example, which  dynamically updates the date/time.</p>
<p>Example 1</p>
<p>First, copy the code below and save it in a file called &#8216;script.js&#8217;:</p>
<pre>var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version &gt;= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp &amp;&amp; typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

function loadFragmentInToElement(fragment_url, element_id) {
    var element = document.getElementById(element_id);
    element.innerHTML = '&lt;em&gt;Loading ...&lt;/em&gt;';
    xmlhttp.open("GET", fragment_url);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
            element.innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.send(null);
}
</pre>
<p>Then copy the code below, and paste it in a file called &#8216;server1.php&#8217;:</p>
<pre>&lt;?php
echo date("l dS of F Y h:i:s A");
?&gt;
</pre>
<p>And finally, copy the code below, and paste it in a file called  &#8216;client1.php&#8217;. Please note though that you need to edit the line that says  &#8216;http://www.yourdomain.com/server1.php&#8217; to the correct location of server1.php  on your server.</p>
<pre>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Example 1&lt;/title&gt;
&lt;script src="script.js" type="text/javascript"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
	function updatedate() {
		loadFragmentInToElement('http://www.yourdomain.com/server1.php', 'currentdate');
	}

&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
	The current date is	&lt;span id="currentdate"&gt;&lt;?php echo date("l dS of F Y h:i:s A"); ?&gt;&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;

	&lt;input type="button" value="Update date" OnClick="updatedate();" /&gt;
&lt;/body&gt;

&lt;/html&gt;
</pre>
<p>Now go to http://www.yourdomain.com/client1.php and click on the button  that says &#8216;Update date&#8217;. The date will update, without the page having to be  reloaded. This is done with the XML HTTP Request object. This example can also  be viewed online at http://www.phpit.net/demo/php%20on%20the%20fly/client1.php<a href="http://web.archive.org/web/20050211201856/http://www.phpit.net/demo/php%20on%20the%20fly/client1.php." target="new">.</a></p>
<p>Example 2</p>
<p>Let&#8217;s try a more advanced example. In the following example, the visitor can  enter two numbers, and they are added up by PHP (and not by JavaScript). This  shows the true power of PHP and the XML HTTP Request Object.</p>
<p>This example uses the same script.js as in the first example, so you don&#8217;t  need to create this again. First, copy the code below and paste it in a file  called &#8216;server2.php&#8217;:</p>
<pre>&lt;?php

// Get numbers
$num1 = intval($_GET['num1']);
$num2 = intval($_GET['num2']);

// Return answer
echo ($num1 + $num2);

?&gt;
</pre>
<p>And then, copy the code below, and paste it in a file called &#8216;client2.php&#8217;.  Please note though that you need to edit the line that says  &#8216;http://www.yourdomain.com/server2.php&#8217; to the correct location of server2.php  on your server.</p>
<pre>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Example 2&lt;/title&gt;
&lt;script src="script.js" type="text/javascript"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
	function calc() {
		num1 = document.getElementById ('num1').value;
		num2 = document.getElementById ('num2').value;

		var element = document.getElementById('answer');
		xmlhttp.open("GET", 'http://www.yourdomain.com/server2.php?num1=' + num1 + '&amp;num2=' + num2);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
				element.value = xmlhttp.responseText;
			}
		}
	    xmlhttp.send(null);
	}
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
	Use the below form to add up two numbers. The answer is calculated by a PHP script, and &lt;em&gt;not&lt;/em&gt; with JavaScript. What's the advantage to this? You can execute server-side scripts (PHP) without having to refresh the page.&lt;br /&gt;&lt;br /&gt;

	&lt;input type="text" id="num1" size="3" /&gt; + &lt;input type="text" id="num2" size="3" /&gt; = &lt;input type="text" id="answer" size="5" /&gt;

	&lt;input type="button" value="Calculate!" OnClick="calc();" /&gt;
&lt;/body&gt;

&lt;/html&gt;
</pre>
<p>When you run this example, you can add up two numbers, using PHP and no  reloading at all! If you can&#8217;t get this example to work, then have a look on http://www.phpit.net/demo/php%20on%20the%20fly/client3.php to see  the example online.</p>
<p>Any Disadvantages&#8230;?</p>
<p>There are only two real disadvantages to this system. First of all, anyone  who has JavaScript turned off, or their browser doesn&#8217;t support the XML HTTP  Request Object will not be able to run it. This means you will have to make sure  that there is a non-JavaScript version, or make sure all your visitors have  JavaScript enabled (e.g. an Intranet application, where you can require JS).</p>
<p>Another disadvantage is the fact that it breaks bookmarks. People won&#8217;t be  able to bookmark your pages, if there is any dynamic content in there. But if  you&#8217;re creating a PHP application (and not a PHP website), then bookmarks are  probably not very useful anyway.</p>
<p>Conclusion</p>
<p>As I&#8217;ve shown you, using two very simple examples, it is entirely possible to  execute PHP scripts, without having to refresh the page. I suggest you read more  about the XML HTTP Request Object (http://jibbering.com/2002/4/httprequest.html) and its  capabilities.</p>
<p>The things you can do are limitless. For example, you could create an  extremely neat paging system, that doesn&#8217;t require reloading at all. Or you  could create a GUI for your PHP application, which behaves exactly like Windows  XP. Just think about it!</p>
<p>Be aware though that JavaScript must be enabled for this to work. Without  JavaScript this will be completely useless. So make sure your visitors support  JavaScript, or create a non-JavaScript version as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpscriptschool.com/php-on-the-fly/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing State-enabled Applications With PHP</title>
		<link>http://www.phpscriptschool.com/developing-state-enabled-applications-with-php</link>
		<comments>http://www.phpscriptschool.com/developing-state-enabled-applications-with-php#comments</comments>
		<pubDate>Thu, 18 Nov 2010 13:15:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[application development]]></category>

		<guid isPermaLink="false">http://www.phpscriptschool.com/?p=14</guid>
		<description><![CDATA[Developing State-enabled Applications With PHPDeveloping State-enabled Applications With PHP by: John L Installment 1 Developing State-enabled Applications With PHP When a user is browsing through a website and is surfing from one web page to another, sometimes the website needs to remember the actions (e.g. choices) performed by the user. For example, in a website [...]]]></description>
			<content:encoded><![CDATA[<table>
<tbody>
<tr>
<td colspan="2" valign="top">Developing State-enabled Applications With PHP<strong>Developing State-enabled Applications With PHP</strong><br />
by: <strong>John L</strong></p>
<p>Installment 1</p>
<p>Developing State-enabled Applications With PHP</p>
<p>When a user is browsing through a website and is surfing from one web page to  another, sometimes the website needs to remember the actions (e.g. choices)  performed by the user. For example, in a website that sells DVDs, the user  typically browses through a list of DVDs and selects individual DVDs for check  out at the end of the shopping session. The website needs to remember which DVDs  the user has selected because the selected items needs to be presented again to  the user when the user checks out. In other words, the website needs to remember  the State &#8211; i.e. the selected items &#8211; of the user&#8217;s browsing activities.</p>
<p>However, HTTP is a Stateless protocol and is ill-equipped to handle States. A  standard HTML website basically provides information to the user and a series of  links that simply directs the user to other related web pages. This Stateless  nature of HTTP allows the website to be replicated across many servers for load  balancing purposes. A major drawback is that while browsing from one page to  another, the website does not remember the State of the browsing session. This  make interactivity almost impossible.</p>
<p>In order to increase interactivity, the developer can use the session  handling features of PHP to augment the features of HTTP in order to remember  the State of the browsing session. The are basically 2 ways PHP does this:</p>
<ol>
<li>Using cookies</li>
<li>Using Sessions</li>
</ol>
<p>The next installment discusses how to manage sessions using cookies&#8230;</p>
<p>Installment 2</p>
<p>Cookies</p>
<p>Cookies are used to store State-information in the browser. Browsers are  allowed to keep up to 20 cookies for each domain and the values stored in the  cookie cannot exceed 4 KB. If more than 20 cookies are created by the website,  only the latest 20 are stored. Cookies are only suitable in instances that do  not require complex session communications and are not favoured by some  developers because of privacy issues. Furthermore, some users disable support  for cookies at their browsers.</p>
<p>The following is a typical server-browser sequence of events that occur when  a cookie is used:</p>
<ol>
<li>The server knows that it needs to remember the State of browsing session</li>
<li>The server creates a cookie and uses the Set-Cookie header field in the HTTP  response to pass the cookie to the browser</li>
<li>The browser reads the cookie field in the HTTP response and stores the  cookie</li>
<li>This cookie information is passed along future browser-server communications  and can be used in the PHP scripts as a variable</li>
</ol>
<p>PHP provides a function called setcookie() to allow easy creation of cookies.  The syntax for setcookie is:</p>
<p>int setcookie(string name, [string val], [int expiration_date], [string  path], string domain, [int secure])</p>
<p>The parameters are:</p>
<ol>
<li>name &#8211; this is a mandatory parameter and is used subsequently to identify  the cookie</li>
<li>value &#8211; the value of the cookie &#8211; e.g. if the cookie is used to store the  name of the user, the value parameter will store the actual name &#8211; e.g. John</li>
<li>expiration_date &#8211; the lifetime of the cookie. After this date, the cookie  expires and is unusable</li>
<li>path &#8211; the path refers to the URL from which the cookie is valid and allowed</li>
<li>domain &#8211; the domain the created the cookie and is allowed to read the  contents of the cookie</li>
<li>secure &#8211; specifies if the cookie can be sent only through a secure  connection &#8211; e.g. SSL enable sessions</li>
</ol>
<p>The following is an example that displays to the user how many times a  specific web page has been displayed to the user. Copy the code below (both the  php and the html) into a file with the .php extension and test it out.</p>
<pre>[?php
//check if the $count variable has been associated with the count cookie
if (!isset($count)) {
    $count = 0;
} else {
    $count++;
}
setcookie("count", $count, time()+600, "/", "", 0);
?]

[html]
    [head]
        [title]Session Handling Using Cookies[/title]
    [/head]
    [body]
        This page has been displayed: [?=$count ?] times.
    [/body]
[/html]
</pre>
<p>The next installment discusses how to manage sessions using PHP session  handling functions with cookies enabled&#8230;</p>
<p>Installment 3</p>
<p>PHP Session Handling &#8211; Cookies Enabled</p>
<p>Instead of storing session information at the browser through the use of  cookies, the information can instead be stored at the server in session files.  One session file is created and maintained for each user session. For example,  if there are three concurrent users browsing the website, three session files  will be created and maintained &#8211; one for each user. The session files are  deleted if the session is explicitly closed by the PHP script or by a daemon  garbage collection process provided by PHP. Good programming practice would call  for sessions to be closed explicitly in the script.</p>
<p>The following is a typical server-browser sequence of events that occur when  a PHP session handling is used:</p>
<ol>
<li>The server knows that it needs to remember the State of browsing session</li>
<li>PHP generates a sssion ID and creates a session file to store future  information as required by subsequent pages</li>
<li>A cookie is generated wih the session ID at the browser</li>
<li>This cookie that stores the session ID is transparently and automatically  sent to the server for all subsequent requests to the server</li>
</ol>
<p>The following PHP session-handling example accomplishes the same outcome as  the previous cookie example. Copy the code below (both the php and the html)  into a file with the .php extension and test it out.</p>
<p>[?php //starts a session session_start(); //informs PHP that count  information needs to be remembered in the session file if  (!session_is_registered("count")) { session_register("count"); $count = 0; }  else { $count++; } $session_id = session_id(); ?] [html] [head] [title]PHP  Session Handling &#8211; Cookie-Enabled[/title] [/head] [body] The current session id  is: [?=$session_id ?] This page has been displayed: [?=$count ?] times. [/body]  [/html]</p>
<p>A summary of the functions that PHP provides for session handling are:</p>
<ol>
<li>boolean start_session() &#8211; initializes a session</li>
<li>string session_id([string id]) &#8211; either returns the current session id or  specify the session id to be used when the session is created</li>
<li>boolean session_register(mixed name [, mixed ...]) &#8211; registers variables to  be stored in the session file. Each parameter passed in the function is a  separate variable</li>
<li>boolean session_is_registered(string variable_name) &#8211; checks if a variable  has been previously registered to be stored in the session file</li>
<li>session_unregister(string varriable_name) &#8211; unregisters a variable from the  session file. Unregistered variables are no longer valid for reference in the  session.</li>
<li>session_unset() &#8211; unsets all session variables. It is important to note that  all the variables remain registered.</li>
<li>boolean session_destroy() &#8211; destroys the session. This is opposite of the  start_session function.</li>
</ol>
<p>The next installment discusses how to manage sessions using PHP session  handling functions when cookies are disabled&#8230;</p>
<p>Installment 4</p>
<p>PHP Session Handling &#8211; Without Cookies</p>
<p>If cookies are disabled at the browser, the above example cannot work. This  is because although the session file that stores all the variables is kept at  the server, a cookie is still needed at the browser to store the session ID that  is used to identify the session and its associated session file. The most common  way around this would be to explicitly pass the session ID back to the server  from the browser as a query parameter in the URL.</p>
<p>For example, the PHP script generates requests subsequent to the  start_session call in the following format:</p>
<p>http://www.yourhost.com/yourphpfile.php?PHPSESSID=[actual session ID]</p>
<p>The following are excerpts that illustrate the discussion:</p>
<p>Manually building the URL:</p>
<p>$url = &#8220;http://www.yoursite.com/yourphppage.php?PHPSESSID=&#8221; . session_id();<br />
[a href="[?=$url ?]&#8220;]Anchor Text[/a]</p>
<p>Building the URL using SID:</p>
<p>[a href="http://www.yoursite.com/yourphppage.php?[?=SID ?]&#8220;]Anchor Text[/a]</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.phpscriptschool.com/developing-state-enabled-applications-with-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP and Cookies; a Good Mix!</title>
		<link>http://www.phpscriptschool.com/php-and-cookies-a-good-mix</link>
		<comments>http://www.phpscriptschool.com/php-and-cookies-a-good-mix#comments</comments>
		<pubDate>Sun, 17 Oct 2010 13:17:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.phpscriptschool.com/?p=16</guid>
		<description><![CDATA[Introduction Cookies have long been used in PHP scripts, and are a very useful function. But what exactly are cookies? Maybe you have used then, but you still don&#8217;t know exactly what they are. Or you are completely new to cookies? It doesn&#8217;t matter, because in this tutorial I will show you exactly what cookies [...]]]></description>
			<content:encoded><![CDATA[<p>Introduction</p>
<p>Cookies have long been used in PHP scripts, and are a very useful function.  But what exactly are cookies? Maybe you have used then, but you still don&#8217;t know  exactly what they are. Or you are completely new to cookies? It doesn&#8217;t matter,  because in this tutorial I will show you exactly what cookies are, and what they  are used for.</p>
<p>Cookies in a nutshell</p>
<p>Cookies are small pieces of information that is stored on the computer of  your visitors. Each browser handles it differently, but most simply store the  information in a small text file. Internet Explorer has a special folder, which  can be found in your C:\Windows or C:\Windows\System32 folder. You can delete  all your cookies, by going to the Options and &#8216;Clearing Cookies&#8217; or deleting  them by hand. I don&#8217;t recommend this though.</p>
<p>Almost every website uses cookies. If you go to Amazon.com, you will get several cookies. The same goes for CNN.com. Even Google uses cookies! They are  extremely useful for (temporarily) storing information. For example, if you have  a login system for your visitors, you could save their userid and password (very  heavily encrypted!) so they are automatically logged in the next time they visit  your website.</p>
<p>Or you could remember their last visit, and highlight everything that is new.  And that&#8217;s just the beginning.</p>
<p>Using Cookies</p>
<p>Using cookies in PHP is extremely easy. In fact, there is nothing to it,  because of PHP&#8217;s inbuilt setcookie() function (http://php.net/setcookie). Have a  look at the documentation, and then try the following example:</p>
<pre>&lt;?php

// Set a cookie
// Cookie name: name
// Cookie value: Dennis Pallett
// Cookie expire: in 24 hours

setcookie ('name', 'Dennis Pallett', time() + (60*60*24));
?&gt;
</pre>
<p>If you run the code above, then a cookie will be set. That&#8217;s all. The cookie  name and value are pretty obvious. The cookie expire is when the cookie expires,  or goes away. Simply use the time() function (http://php.net/time) and add the  number of seconds you want to have the cookie available to it. In the example I  added 60*60*24=86400 seconds, or 24 hours.</p>
<p>If you have looked at the documentation, you probably noticed there are  additional arguments. As the documentation says, the path is to limit a cookie  to a specific path on your web server. This is often used when you run multiple  instances of the same script in separate directories. You can safely omit this  argument when it doesn&#8217;t matter if the cookie is available site-wide.</p>
<p>There is also the domain argument. This can be used to limit the cookie to a  specific sub-domain, e.g. test.example.com. You can also safely ignore this argument, or  set it to .example.com (note the  beginning period, this is essential!).</p>
<p>Finally, there is also the secure argument. This argument is only used for  cookies that are sent over a secure HTTPS connection (SSL). Just ignore this  argument, unless you&#8217;re working with a secure connection.</p>
<p>One thing that should be mentioned is that cookies must be set, before you  display any HTML/text. It&#8217;s probably best if you turn on output buffering by  putting ob_start() (http://php.net/ob_start) at the top of your page.</p>
<p>Now that you have set a cookie, you probably want to retrieve the value as  well. After all, that is the whole point of using cookies. Thankfully, as PHP is  ever so easy, you can retrieve the same way as you retrieve a GET value. See the  following example to retrieve the value of the previous example:</p>
<pre>&lt;?php
echo 'Your name is ' . $_COOKIE['name'];
?&gt;
</pre>
<p>This should print &#8220;Your name is Dennis Pallett&#8221;. There&#8217;s nothing more to it.  It&#8217;s just that easy!</p>
<p>Finally, one thing you probably want to do as well is remove cookies. This is  as easy as setting them. Simply change the value of the cookie to FALSE, and  change the expire date to -3000 seconds. See the following example:</p>
<pre>&lt;?php
setcookie ('name', FALSE, time()-1000);
?&gt;
</pre>
<p>Checking if cookies are enabled</p>
<p>Before you start using cookies, you must make sure your visitor has cookies  enabled. This can be done with a simply PHP checking script. Unfortunately, the  PHP page needs to reload to check for cookies. But this can be done very  transparently, and your visitor should hardly notice anything.</p>
<p>The following example will first set a test cookie, then reload the page, and  finally check whether cookies are enabled.</p>
<pre>&lt;?php
error_reporting (E_ALL ^ E_WARNING ^ E_NOTICE);

// Check if cookie has been set or not
if ($_GET['set'] != 'yes') {
	// Set cookie
	setcookie ('test', 'test', time() + 60);

	// Reload page
	header ("Location: checkcookies.php?set=yes");
} else {
	// Check if cookie exists
	if (!empty($_COOKIE['test'])) {
		echo "Cookies are enabled on your browser";
	} else {
		echo "Cookies are &lt;b&gt;NOT&lt;/b&gt; enabled on your browser";
	}
}
?&gt;
</pre>
<p>Run the code above, and see what the output is. Check if cookies are enabled  in your browser. If they&#8217;re not enabled, then you can enable them by going to  your browser&#8217;s options. Unfortunately, this is different from each browser, so I  can&#8217;t give you exact instructions. But Google can.</p>
<p>Storing Arrays</p>
<p>One feature of cookies that is often missed in articles is the ability to  story arrays. Cookies can be used to store multi-dimensional arrays, which can  be extremely useful to store data.</p>
<p>Consider the following code;</p>
<pre>&lt;?php
setcookie ("name[first]", "Dennis", time() + (60*60*24));
setcookie ("name[last]", "Pallett", time() + (60*60*24));
?&gt;
</pre>
<p>You can then display these two cookies using the following code:</p>
<pre>&lt;?php
echo "First Name: " . $_COOKIE['name']['first'];
echo "&lt;br /&gt;Last Name: " . $_COOKIE['name']['last'];
?&gt;
</pre>
<p>The cookie &#8216;name&#8217; is an array, and has multiple values. You can even go  deeper and have multi-dimensional arrays, e.g.  $_COOKIE['name']['test']['something']['value']. You could store whole arrays of  data in cookies. But beware that you don&#8217;t store too much data, there are  certain size limits to cookies.</p>
<p>In Conclusion&#8230;</p>
<p>Cookies are really versatile, and can be used for a lot of different  purposes. Many websites use cookies, and cookies can really make your website  more personalized. Using cookies in PHP isn&#8217;t hard at all, and you should be  able to use them without any difficulty.</p>
<p>Before actively using cookies in your website, you must check whether the  visitor has enabled them in their browser. If they don&#8217;t have cookies enabled,  you must either redirect to a non-cookies version of your website, or you can  make sure your website also works without cookies.</p>
<p>You can download a sample script at http://www.phpit.net/demo/php%20and%20cookies/logger.zip, where  cookies are used in a (somewhat) practical way. In this example, there is a  logging module, called log.php and a display module, called history.php.  Basically, you include the log.php in other PHP pages, and then you can view  history.php to lookup all the pages you have viewed and how often. The example  uses arrays, and stores them in cookies.</p>
<p>The examples in this article can be downloaded at http://www.phpit.net/demo/php%20and%20cookies/examples.zip.</p>
<p>If you have a really unique practical way of using cookies, please let me  know at dennis [AT] nocertainty [DOT] com. I&#8217;d really like to hear about  interesting ways of using cookies.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpscriptschool.com/php-and-cookies-a-good-mix/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Your first PHP-enabled page</title>
		<link>http://www.phpscriptschool.com/your-first-php-enabled-page</link>
		<comments>http://www.phpscriptschool.com/your-first-php-enabled-page#comments</comments>
		<pubDate>Sun, 30 May 2010 13:18:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.phpscriptschool.com/?p=18</guid>
		<description><![CDATA[Create a file named hello.php and put it in your web server&#8217;s root directory (DOCUMENT_ROOT) with the following content: Example 2-1. Our first PHP script: hello.php &#60;html&#62; &#60;head&#62; &#60;title&#62;PHP Test&#60;/title&#62; &#60;/head&#62; &#60;body&#62; &#60;?php echo '&#60;p&#62;Hello World&#60;/p&#62;'; ?&#62; &#60;/body&#62; &#60;/html&#62; Use your browser to access the file with your web server&#8217;s URL, ending with the &#8220;/hello.php&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Create a file named <tt>hello.php</tt> and put it in your web  server&#8217;s root directory (<var>DOCUMENT_ROOT</var>) with the  following content:</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<div>
<p><a name="AEN174"></a></p>
<p><strong>Example 2-1. Our first PHP script: <tt>hello.php</tt></strong></p>
<table border="0" cellpadding="5" bgcolor="#e0e0e0">
<tbody>
<tr>
<td>
<div>
<p><code>&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;PHP Test&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;?php echo '&lt;p&gt;Hello World&lt;/p&gt;';  ?&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt; </code></p>
</div>
</td>
</tr>
</tbody>
</table>
<p>Use your browser to access the file with your web server&#8217;s URL, ending with  the &#8220;/hello.php&#8221; file reference. When developing locally this URL will be  something like <var>http://localhost/hello.php</var> or <var>http://127.0.0.1/hello.php</var> but this depends on the web  server&#8217;s configuration. If everything is configured correctly, this file will be  parsed by PHP and the following output will be sent to your browser:</p>
<table border="0" cellpadding="5" bgcolor="#e0e0e0">
<tbody>
<tr>
<td>
<pre>&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;PHP Test&lt;/title&gt;
 &lt;/head&gt;
 &lt;body&gt;
 &lt;p&gt;Hello World&lt;/p&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
<p>This program is extremely simple and you really did not need to use PHP to  create a page like this. All it does is display: <var>Hello  World</var> using the PHP <a><strong>echo()</strong></a> statement. Note that the file <em>does not need to be executable</em> or  special in any way. The server finds out that this file needs to be interpreted  by PHP because you used the &#8220;.php&#8221; extension, which the server is configured to  pass on to PHP. Think of this as a normal HTML file which happens to have a set  of special tags available to you that do a lot of interesting things.</p>
<p>If you tried this example and it did not output anything, it prompted for  download, or you see the whole file as text, chances are that the server you are  on does not have PHP enabled, or is not configured properly. Ask your  administrator to enable it for you using the <a>Installation</a> chapter of the manual. If you are developing  locally, also read the installation chapter to make sure everything is  configured properly. Make sure that you access the file via http with the server  providing you the output. If you just call up the file from your file system,  then it will not be parsed by PHP. If the problems persist anyway, do not  hesitate to use one of the many <a>PHP  support</a> options.</p>
<p>The point of the example is to show the special PHP tag format. In this  example we used <var>&lt;?php</var> to indicate the start of a PHP  tag. Then we put the PHP statement and left PHP mode by adding the closing tag,  <var>?&gt;</var>. You may jump in and out of PHP mode in an HTML  file like this anywhere you want. For more details, read the manual section on  the <a>basic PHP syntax</a>.</p>
<div>
<blockquote><p><strong>A Note on Text Editors: </strong>There are many text editors and Integrated  Development Environments (IDEs) that you can use to create, edit and manage PHP  files. A partial list of these tools is maintained at <a target="_top">PHP Editors  List</a>. If you wish to recommend an editor, please visit the above page and  ask the page maintainer to add the editor to the list. Having an editor with  syntax highlighting can be helpful.</p>
<p><strong>A Note on Word Processors: </strong>Word processors such as StarOffice Writer,  Microsoft Word and Abiword are not optimal for editing PHP files. If you wish to  use one for this test script, you must ensure that you save the file as <em>plain text</em> or PHP will not be able  to read and execute the script.</p>
<p><strong>A Note on Windows Notepad: </strong>If you are writing your PHP scripts using  Windows Notepad, you will need to ensure that your files are saved with the .php  extension. (Notepad adds a .txt extension to files automatically unless you take  one of the following steps to prevent it.) When you save the file and are  prompted to provide a name for the file, place the filename in quotes (i.e. &#8220;<tt>hello.php</tt>&#8220;). Alternatively, you can click on the &#8216;Text  Documents&#8217; drop-down menu in the &#8216;Save&#8217; dialog box and change the setting to  &#8220;All Files&#8221;. You can then enter your filename without quotes.</p></blockquote>
</div>
<p>Now that you have successfully created a working PHP script, it is time to  create the most famous PHP script! Make a call to the <a><strong>phpinfo()</strong></a> function and you  will see a lot of useful information about your system and setup such as  available <a>predefined variables</a>,  loaded PHP modules, and <a>configuration</a> settings.  Take some time and review this important information.</p>
<p><a name="AEN210"></a></p>
<p><strong>Example 2-2. Get system information from PHP</strong></p>
<div>
<p><code>&lt;?php  phpinfo(); ?&gt; </code></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.phpscriptschool.com/your-first-php-enabled-page/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sample script with PHP-CGI</title>
		<link>http://www.phpscriptschool.com/sample-script-with-php-cgi</link>
		<comments>http://www.phpscriptschool.com/sample-script-with-php-cgi#comments</comments>
		<pubDate>Sat, 05 Dec 2009 13:14:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.phpscriptschool.com/?p=12</guid>
		<description><![CDATA[Well, as a follow-up to our PHPCGI tutorial that showed you how to install the PHP files as a CGI program on your server, we wanted to get a bit more into some of the details of using it and running scripts automatically with it. Once again, we&#8217;re going to assume that it&#8217;s a UNIX-based [...]]]></description>
			<content:encoded><![CDATA[<p>Well, as a follow-up to our PHPCGI tutorial that showed you how  to install the PHP files as a CGI program on your server, we wanted to get a bit  more into some of the details of using it and running scripts automatically with  it. Once again, we&#8217;re going to assume that it&#8217;s a UNIX-based operating system  you&#8217;re working on. This is much easier to get working than a Windows based  machine (well, for me anyway) and cron just does such a good job, we&#8217;re going to  stick with it. &lt;p&gt; Anyway, for those out there that aren&#8217;t too  linux-literate and aren&#8217;t exactly sure how to set up a cron job, we&#8217;re here to  help. I&#8217;m going to give you a crash course in setting them up and then show you  how to get a nice little PHP script working with it. This will let you make some  nice scripts and allow you to (possibly) transfer some of the admin portions of  your site to a well-written PHP script in a cron job.</p>
<p>So, on with cron:  cron is actaully the name of the daemon that any good sysadmin runs on their  systems to make their lives easier. For the most part, the server you&#8217;re working  on should have the cron daemon running and working properly. Otherwise, you&#8217;ll  need to contact your friendly neighborhood sysadmin and get them to fix what  they broke. Once you&#8217;re sure that they have it up and working (if it wasn&#8217;t in  the first place), then you can go on from here.</p>
<p>The cron daemon looks at  something called the &#8220;crontab&#8221; to get the scripts and their parameters that it  needs to run. You set all of this info in one place &#8211; the script to be run and  the time(s) when this needs to be done. The syntax for the crontab is pretty  easy to figure out and can be accessed easily with the following  command:</p>
<p>crontab -e</p>
<p>This should bring up your crontab file. Most  likely, unless you&#8217;ve messed with cron stuff before (in which case you probably  wouldn&#8217;t be reading this). You now have a nice clean crontab to mess with. Now,  the fun of the syntax &#8211; the fields go in this order and are separated by spaces:  minute, hour, day of month, month, day of week, then the script to be run. Now,  this is all well and good, but how do you actually use it to make a script run?  Well, it&#8217;s pretty simple really. For example:</p>
<p>5 0 * * *  /bin/ls</p>
<p>would run the &#8220;ls&#8221; command every day at five minutes after  midnight. There are tons of combinations that you can have for all of the times  and numbers you can put in. For more info on that, check out the &#8220;man 5 crontab&#8221;  command and read the info in there. Now, obviously this is kind of a silly  example, but that&#8217;s all it is. Now, we&#8217;ll show you how it can actually be  useful.</p>
<p>Say we have a site that, each night at five after midnight, you  want it to send out emails to everyone that has some kind of money due by the  end of the next day. We have our PHP  script:</p>
<p>&lt;?php<br />
$sql=mysql_connect(&#8220;localhost&#8221;,&#8221;username&#8221;,&#8221;password&#8221;);<br />
$fetch=mysql_query(&#8220;select  * from users where balance_due&gt;1000);<br />
// insert more useful code  here<br />
?&gt;</p>
<p>You get the idea&#8230;the code that&#8217;s in the file isn&#8217;t the  important part right now. What&#8217;s important is having it set up right with the  cron job. Now, if we use our example from above (and assume that PHP is already  compiled as a CGI), then we can safely set this in the crontab:</p>
<p>5 0 * * *  /usr/local/bin/php /path/to/file.php</p>
<p>You&#8217;ll have to substitute your  locations and all when you get those pinned down, but other than that, that  should be all that you need. You should now have a PHP script that updates your  database nightly at 12:05 (00:05 for you 24-hr buffs, hence the 0). There are  tons of neat uses for this besides getting updates to run and all, but this is  one of the main ones that I&#8217;ve found it used for.<br />
Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpscriptschool.com/sample-script-with-php-cgi/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

