Software Information



Articles Main Page | Main Site Home Page





Text Ad's by TextAdPro.com
Make Money For Real doing nothing - 3 ways to profit - EZmatic.com.

ThatsNeato.com - That's Neato!

Home Business Money Making - How to make money on the net.

2coolhair.com - Over 5,000 Hairstyles Pitcures.



PHP On-The-Fly!


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'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.

The internet wasn'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're building a PHP application (e.g. a high-quality content management system), then it'd be ideal if it worked almost like a native Windows/Linux application.

But that requires real-time updates. Something that isn't possible, or so you would think. A good example of an application that works in (almost) real-time is Google's GMail (http://gmail.google.com). Everything is JavaScript powered, and it'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'm going to show you in this article.

How does it work?

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 1x1 iframe, where a new PHP page is loaded, but this is far from ideal.

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+).

With this object and some custom JavaScript functions, you can create some rather impressive PHP applications. Let's look at a first example, which dynamically updates the date/time.

Example 1

First, copy the code below and save it in a file called 'script.js':

var xmlhttp=false;

/*@cc_on @*/

/*@if (@_jscript_version >= 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 && typeof XMLHttpRequest!='undefined') {

xmlhttp = new XMLHttpRequest();

}

function loadFragmentInToElement(fragment_url, element_id) {

var element = document.getElementById(element_id);

element.innerHTML = 'Loading ...';

xmlhttp.open("GET", fragment_url);

xmlhttp.onreadystatechange = function() {

if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

element.innerHTML = xmlhttp.responseText;

}

}

xmlhttp.send(null);

}

Then copy the code below, and paste it in a file called 'server1.php':

And finally, copy the code below, and paste it in a file called 'client1.php'. Please note though that you need to edit the line that says 'http://www.yourdomain.com/server1.php' to the correct location of server1.php on your server.

Example 1

function updatedate() {

loadFragmentInToElement('http://www.yourdomain.com/server1.php', 'currentdate');

}

The current date is .

Now go to http://www.yourdomain.com/client1.php and click on the button that says 'Update date'. 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.

Example 2

Let'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.

This example uses the same script.js as in the first example, so you don't need to create this again. First, copy the code below and paste it in a file called 'server2.php':

And then, copy the code below, and paste it in a file called 'client2.php'. Please note though that you need to edit the line that says 'http://www.yourdomain.com/server2.php' to the correct location of server2.php on your server.

Example 2

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 + '&num2=' + num2);

xmlhttp.onreadystatechange = function() {

if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

element.value = xmlhttp.responseText;

}

}

xmlhttp.send(null);

}

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

+ =

When you run this example, you can add up two numbers, using PHP and no reloading at all! If you can'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.

Any Disadvantages...?

There are only two real disadvantages to this system. First of all, anyone who has JavaScript turned off, or their browser doesn'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).

Another disadvantage is the fact that it breaks bookmarks. People won't be able to bookmark your pages, if there is any dynamic content in there. But if you're creating a PHP application (and not a PHP website), then bookmarks are probably not very useful anyway.

Conclusion

As I'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.

The things you can do are limitless. For example, you could create an extremely neat paging system, that doesn'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!

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.

About The Author

Dennis Pallett is a young tech writer, with much experience in ASP, PHP and other web technologies. He enjoys writing, and has written several articles and tutorials. To find more of his work, look at his websites at http://www.phpit.net http://www.aspit.net and http://www.ezfaqs.com

dennispallett@gmail.com


MORE RESOURCES:
table border=0 width= valign=top cellpadding=2 cellspacing=7trtd valign=top class=jfont style=font-size:85%;font-family:arial,sans-serifbrdiv style=padding-top:0.8em;img alt= height=1 width=1/divdiv class=lha href=http://news.google.com/news/url?sa=Tct=us/0-0fd=Rurl=http://www.tradingmarkets.com/.site/news/Stock%2520News/2108178/cid=1287334473ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNESwEXPlauohv1epjxBZNVAQFdGzAUltimate bSoftware/b to Present at the Needham Growth Stock Conference/abrfont size=-1font color=#6f6f6fTrading Markets (press release),nbsp;CAnbsp;-/font nobr8 hours ago/nobr/fontbrfont size=-1Scherr and Dauerman will discuss Ultimate bSoftware#39;s/b recurring revenue business, as well as an overview of the company#39;s history and financial results. b.../b/fontbrfont size=-1a href=http://news.google.com/news/url?sa=Tct=us/0-1fd=Rurl=http://www.marketwatch.com/news/story/callidus-software-presents-11th-annual/story.aspx%3Fguid%3D%257B284A7760-4B71-4F71-9817-B0F5452AD99A%257D%26dist%3Dmsr_2cid=1287334473ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNG4F8dJ-rjlXu5rg_MoN1r_82GTDACallidus bSoftware/b Presents at 11th Annual Needham Growth Stock b.../b/a font size=-1 color=#6f6f6fnobrMarketWatch (press release)/nobr/font/fontbrfont class=p size=-1a class=p href=http://news.google.com/news?sourceid=navclientie=ISO-8859-1rls=GGLG,GGLG:2005-22,GGLG:enncl=1287334473hl=ennobrall 15 news articles/nobr/a/font/div/font/td/tr/table

table border=0 width= valign=top cellpadding=2 cellspacing=7trtd valign=top class=jfont style=font-size:85%;font-family:arial,sans-serifbrdiv style=padding-top:0.8em;img alt= height=1 width=1/divdiv class=lha href=http://news.google.com/news/url?sa=Tct=us/1-0fd=Rurl=http://www.msnbc.msn.com/id/28504693/cid=1287237091ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNH7i3XFVaLKkt9qw8vuHQvH_UFplQMagic bSoftware/b Appoints Hadas Gazit-Kaiser as Its Chief Financial b.../b/abrfont size=-1font color=#6f6f6fMSNBCnbsp;-/font nobr1 hour ago/nobr/fontbrfont size=-1Ms. Gazit-Kaiser, a board member of Magic bSoftware/b, replaces Mr. Zigdon as the Company#39;s CFO. Ms. Gazit-Kaiser joins Magic bSoftware/b from Emblaze, b.../b/fontbrfont size=-1a href=http://news.google.com/news/url?sa=Tct=us/1-1fd=Rurl=http://news.moneycentral.msn.com/provider/providerarticle.aspx%3Ffeed%3DBCOM%26date%3D20090105%26id%3D9485145cid=1287237091ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNFj2oEYNF_0jRDC6U4s7imkQ-zTPAMarket Report -- In Play (MGIC)/a font size=-1 color=#6f6f6fnobrMSN Money/nobr/font/fontbrfont size=-1a href=http://news.google.com/news/url?sa=Tct=us/1-2fd=Rurl=http://www.sharecast.com/cgi-bin/sharecast/story.cgi%3Fstory_id%3D2537342cid=1287237091ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNEefDbkyFMC-bNuYPsGRcWzzJPeOATechMARK movers: Emblaze shares down/a font size=-1 color=#6f6f6fnobrShareCast/nobr/font/fontbrfont class=p size=-1a class=p href=http://news.google.com/news?sourceid=navclientie=ISO-8859-1rls=GGLG,GGLG:2005-22,GGLG:enncl=1287237091hl=ennobrall 15 news articles/nobr/a/font/div/font/td/tr/table

table border=0 width= valign=top cellpadding=2 cellspacing=7trtd valign=top class=jfont style=font-size:85%;font-family:arial,sans-serifbrdiv style=padding-top:0.8em;img alt= height=1 width=1/divdiv class=lha href=http://news.google.com/news/url?sa=Tct=us/2-0fd=Rurl=http://www.bizjournals.com/kansascity/stories/2009/01/05/daily8.htmlcid=1287329548ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNFCTP3FoUfORWTAwOouOpqRwoJ95QPerceptive bSoftware/b lays off 53 Kansas City Business Journal/abrfont size=-1font color=#6f6f6fBizjournals.com,nbsp;NCnbsp;-/font nobr15 hours ago/nobr/fontbrfont size=-1In a second round of cuts, Perceptive bSoftware/b Inc. laid off 53 employees on Monday, or 10 percent of its work force. The cuts, announced to employees b.../b/fontbrfont size=-1a href=http://news.google.com/news/url?sa=Tct=us/2-1fd=Rurl=http://www.kansascity.com/business/story/965873.htmlcid=1287329548ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNHjbaWdQ7tskKbtRIrna0x33H223wPerceptive bSoftware/b lays off 53 workers/a font size=-1 color=#6f6f6fnobrKansas City Star/nobr/font/fontbrfont size=-1a href=http://news.google.com/news/url?sa=Tct=us/2-2fd=Rurl=http://www.shawneedispatch.com/news/2009/jan/05/software-firm-cuts-more-jobs/cid=1287329548ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNEWkXkZGxcoolC5zp82VcDDouLd9wbSoftware/b firm cuts more jobs/a font size=-1 color=#6f6f6fnobrShawnee Dispatch/nobr/font/fontbrfont class=p size=-1a class=p href=http://news.google.com/news?sourceid=navclientie=ISO-8859-1rls=GGLG,GGLG:2005-22,GGLG:enncl=1287329548hl=ennobrall 7 news articles/nobr/a/font/div/font/td/tr/table

table border=0 width= valign=top cellpadding=2 cellspacing=7trtd valign=top class=jfont style=font-size:85%;font-family:arial,sans-serifbrdiv style=padding-top:0.8em;img alt= height=1 width=1/divdiv class=lha href=http://news.google.com/news/url?sa=Tct=us/3-0fd=Rurl=http://www.reuters.com/article/pressRelease/idUS101412%2B05-Jan-2009%2BBW20090105cid=1287231874ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNFX8l-UU1VlrIKYFVedvXmAYiPc7wPerkinElmer and IDBS Announce bSoftware/b Collaboration to Improve b.../b/abrfont size=-1font color=#6f6f6fReutersnbsp;-/font nobr23 hours ago/nobr/fontbrfont size=-1PerkinElmer`s Columbus bsoftware/b is a flexible, convenient solution for high volume image storage and management. Designed as a partner product for the Opera b.../b/fontbrfont size=-1a href=http://news.google.com/news/url?sa=Tct=us/3-1fd=Rurl=http://www.genomeweb.com/issues/news/151602-1.htmlcid=1287231874ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNGMfLm2dcGJvS4XYcdyqjE9pg91ewPerkinElmer, IDBS Integrate Data Management and Storage bSoftware/b/a font size=-1 color=#6f6f6fnobrGenomeWeb News/nobr/font/fontbrfont size=-1a href=http://news.google.com/news/url?sa=Tct=us/3-2fd=Rurl=http://www.reuters.com/article/pressRelease/idUS101415%2B05-Jan-2009%2BBW20090105cid=1287231874ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNEWdQJwpXibkrMKVfRKx4XrLzkDfQPerkinElmer Launches Operetta High Content Screening (HCS) System/a font size=-1 color=#6f6f6fnobrReuters/nobr/font/fontbrfont class=p size=-1a class=p href=http://news.google.com/news?sourceid=navclientie=ISO-8859-1rls=GGLG,GGLG:2005-22,GGLG:enncl=1287231874hl=ennobrall 23 news articles/nobr/a/font/div/font/td/tr/table

table border=0 width= valign=top cellpadding=2 cellspacing=7trtd valign=top class=jfont style=font-size:85%;font-family:arial,sans-serifbrdiv style=padding-top:0.8em;img alt= height=1 width=1/divdiv class=lha href=http://news.google.com/news/url?sa=Tct=us/4-0fd=Rurl=http://www.reuters.com/article/pressRelease/idUS82934%2B05-Jan-2009%2BBW20090105cid=1287205999ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNEUUz0e8ooic_YaCdUqiez092fuygInsider bSoftware/b to Unveil TypeTrax at Macworld Expo: Represents b.../b/abrfont size=-1font color=#6f6f6fReutersnbsp;-/font nobrJan 5, 2009/nobr/fontbrfont size=-1New Digital Asset bSoftware/b Tracks Projects, Font Usage and Automatically Preflights InDesign and Illustrator Jobs LOS GATOS, California--(Business Wire)-- b.../b/fontbrfont size=-1a href=http://news.google.com/news/url?sa=Tct=us/4-1fd=Rurl=http://stuff.techwhack.com/5956-typetraxcid=1287205999ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNFwUC51uLXpLI-neMpomrHADfsXCAInsider bSoftware/b launches TypeTrax/a font size=-1 color=#6f6f6fnobrTechWhack/nobr/font/fontbrfont size=-1a href=http://news.google.com/news/url?sa=Tct=us/4-2fd=Rurl=http://www.macworld.com/article/137910/2009/01/typetrax.htmlcid=1287205999ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNGniU8GbeLvH8mMpzkrSuEJGvy3xQExpo: TypeTrax manages Creative Suite projects/a font size=-1 color=#6f6f6fnobrMacworld/nobr/font/fontbrfont size=-1a href=http://news.google.com/news/url?sa=Tct=us/4-3fd=Rurl=http://www.macnn.com/articles/09/01/05/insider.releases.typetrax/cid=1287205999ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNFP_gf9fXuLdVi0of597ZR2OnZbCwTypeTrax manages Adobe CS documents, fonts, more/a font size=-1 color=#6f6f6fnobrMacNN/nobr/font/fontbrfont class=p size=-1a class=p href=http://news.google.com/news?sourceid=navclientie=ISO-8859-1rls=GGLG,GGLG:2005-22,GGLG:enncl=1287205999hl=ennobrall 24 news articles/nobr/a/font/div/font/td/tr/table

table border=0 width= valign=top cellpadding=2 cellspacing=7trtd valign=top class=jfont style=font-size:85%;font-family:arial,sans-serifbrdiv style=padding-top:0.8em;img alt= height=1 width=1/divdiv class=lha href=http://news.google.com/news/url?sa=Tct=us/5-0fd=Rurl=http://www.reuters.com/article/pressRelease/idUS111716%2B05-Jan-2009%2BBW20090105cid=1287229405ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNFPxJJgBt1O4BVI-XnJzBbqBO3NEQZyLAB Receives Highest Rating in Research Firm`s E-Discovery b.../b/abrfont size=-1font color=#6f6f6fReutersnbsp;-/font nobr23 hours ago/nobr/fontbrfont size=-1quot;ZyLAB offers a very robust end-to-end e-discovery bsoftware/b platform that is ideally suited for numerous organizations ranging from law firms, corporations, b.../b/fontbrfont size=-1a href=http://news.google.com/news/url?sa=Tct=us/5-1fd=Rurl=http://www.msnbc.msn.com/id/28504084/cid=1287229405ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNEH6fPr0cboJq9uyiYI9c5kdkX2pgClearwell Systems Receives Highest Rating in Leading Analyst b.../b/a font size=-1 color=#6f6f6fnobrMSNBC/nobr/font/fontbrfont class=p size=-1a class=p href=http://news.google.com/news?sourceid=navclientie=ISO-8859-1rls=GGLG,GGLG:2005-22,GGLG:enncl=1287229405hl=ennobrall 14 news articles/nobr/a/font/div/font/td/tr/table

table border=0 width= valign=top cellpadding=2 cellspacing=7trtd valign=top class=jfont style=font-size:85%;font-family:arial,sans-serifbrdiv style=padding-top:0.8em;img alt= height=1 width=1/divdiv class=lha href=http://news.google.com/news/url?sa=Tct=us/6-0fd=Rurl=http://www.macworld.com/article/137911/modelbaker.htmlcid=1287261884ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNEot3mq7sIW_9pHLeGT44kyUXBcNQExpo: ModelBaker rapid app development bsoftware/b debuts/abrfont size=-1font color=#6f6f6fMacworld,nbsp;CAnbsp;-/font nobr19 hours ago/nobr/fontbrfont size=-1by Peter Cohen, Macworld.com Widget Press on Monday announced ModelBaker 1.0, a new rapid application development tool for Mac OS X. It costs $399 for a b.../b/font/div/font/td/tr/table

table border=0 width= valign=top cellpadding=2 cellspacing=7trtd valign=top class=jfont style=font-size:85%;font-family:arial,sans-serifbrdiv style=padding-top:0.8em;img alt= height=1 width=1/divdiv class=lha href=http://news.google.com/news/url?sa=Tct=us/7-0fd=Rurl=http://www.msnbc.msn.com/id/28504492/cid=1287219587ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNFFlCv69e93_63ttlJh1l6OiV4GhgAntenna bSoftware/b Positioned in the Leaders Quadrant in the Magic b.../b/abrfont size=-1font color=#6f6f6fMSNBCnbsp;-/font nobr3 hours ago/nobr/fontbrfont size=-1JERSEY CITY, NJ - Antenna bSoftware/b, delivering real business mobility to the world#39;s most demanding enterprises, today announced that it has been positioned b.../b/fontbrfont size=-1a href=http://news.google.com/news/url?sa=Tct=us/7-1fd=Rurl=http://au.sys-con.com/node/797214cid=1287219587ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNHaYYpJDu1b-uuqTghTPwrN1rqMEQAntenna bSoftware/b Recaps 2008 Successes/a font size=-1 color=#6f6f6fnobrSYS-CON Media/nobr/font/fontbrfont size=-1a href=http://news.google.com/news/url?sa=Tct=us/7-2fd=Rurl=http://www.msnbc.msn.com/id/28503398/cid=1287219587ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNEV2B04n-j_KxnXon7y_spMBlYqYABigFix Positioned in the Visionaries Quadrant in Leading Industry b.../b/a font size=-1 color=#6f6f6fnobrMSNBC/nobr/font/fontbrfont class=p size=-1a class=p href=http://news.google.com/news?sourceid=navclientie=ISO-8859-1rls=GGLG,GGLG:2005-22,GGLG:enncl=1287219587hl=ennobrall 61 news articles/nobr/a/font/div/font/td/tr/table

table border=0 width= valign=top cellpadding=2 cellspacing=7trtd valign=top class=jfont style=font-size:85%;font-family:arial,sans-serifbrdiv style=padding-top:0.8em;img alt= height=1 width=1/divdiv class=lha href=http://news.google.com/news/url?sa=Tct=us/8-0fd=Rurl=http://newsticker.welt.de/%3Fmodule%3Dsmarthouse%26id%3D828433cid=1287470699ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNEwT1ol5ojx5Un6oUOmXppbZE5CSgSmith Micro’s Connection Management bSoftware/b Tapped for Clear b.../b/abrfont size=-1font color=#6f6f6fWELT ONLINE,nbsp;Germanynbsp;-/font nobrJan 5, 2009/nobr/fontbrfont size=-1Smith Micro bSoftware/b, Inc. (NASDAQ:SMSI), a leading developer and marketer of mobility solutions and services for the wireless market, today announced it b.../b/font/div/font/td/tr/table

table border=0 width= valign=top cellpadding=2 cellspacing=7trtd valign=top class=jfont style=font-size:85%;font-family:arial,sans-serifbrdiv style=padding-top:0.8em;img alt= height=1 width=1/divdiv class=lha href=http://news.google.com/news/url?sa=Tct=us/9-0fd=Rurl=http://www.reuters.com/article/pressRelease/idUS87949%2B05-Jan-2009%2BPRN20090105cid=1287206015ei=yGJjSb_gMdmpmQey8tHsAwusg=AFQjCNHkdaumiUXOHOrMXDLwraYJImwPGwRainmaker Signs Three-Year Renewal with TIBCO bSoftware/b for b.../b/abrfont size=-1font color=#6f6f6fReutersnbsp;-/font nobrJan 5, 2009/nobr/fontbrfont size=-1Rainmaker#39;s ViewCentral platform is an external facing Learning Management System that is an online, 24X7 available, bSoftware/b-as-a-Service (SaaS). b.../b/font/div/font/td/tr/table

Software - Google News




Articles Home Page | Site Map | Main Site Home Page
GETsonic | TrafficFish | WildThingsDesigns | NeatoDomains.com | Games | Ken J Wagner | iNetcome

© 2008