Saturday, June 21, 2008

Windows Multimedia Formats

Windows media files have the extensions: .asf, .asx, .wma, and .wmv.
The ASF Format

The ASF format (Advanced Streaming Format) is specially designed to run over the Internet.

ASF files can contain audio, video, slide shows, and synchronized events.

ASF files can be highly compressed and can be delivered as a continuous flow of data (on-line TV or radio). Files can be of any size, and can be compressed to match many different bandwidths (connection speeds).
The ASX Format

ASX (Advanced Stream Redirector) files are not media files, but metafiles.

Metafiles provides information about files. ASX files are plain text files used to describe multimedia content:


Holiday 2001











The file above describes three multimedia files. When the ASX file is read by a player, the player can play the files described.
The WMA Format

The WMA (Windows Media Audio) format is an audio format developed by Microsoft.

WMA is designed to handle all types of audio content. The files can be highly compressed and can be delivered as a continuous flow of data (on-line radio). WMA files can be of any size, and be compressed to match many different bandwidths (connection speeds).

The WMA format is similar to the ASF format (see above)
The WMV Format

The WMV (Windows Media Video) format is a video format developed by Microsoft.

WMV is designed to handle all types of video content. The files can be highly compressed and can be delivered as a continuous flow of data (on-line radio). WMV files can be of any size, and be compressed to match many different bandwidths (connection speeds).

The WMV format is similar to the ASF format (see above)
Other Windows Media Formats

WAX (Windows Media Audio Redirector) files are much the same as ASX files, but intended to describe audio files (.wma files)

WMP (Windows Media Player) files and WMX are reserved file types for future use by Windows.

Multimedia Video Formats

Video can be stored in many different formats.
The AVI Format

The AVI (Audio Video Interleave) format was developed by Microsoft.

The AVI format is supported by all computers running Windows, and by all the most popular web browsers. It is a very common format on the Internet, but not always possible to play on non-Windows computers.

Videos stored in the AVI format have the extension .avi.
The Windows Media Format

The Windows Media format is developed by Microsoft.

Windows Media is a common format on the Internet, but Windows Media movies cannot be played on non-Windows computer without an extra (free) component installed. Some later Windows Media movies cannot play at all on non-Windows computers because no player is available.

Videos stored in the Windows Media format have the extension .wmv.
The MPEG Format

The MPEG (Moving Pictures Expert Group) format is the most popular format on the Internet. It is cross-platform, and supported by all the most popular web browsers.

Videos stored in the MPEG format have the extension .mpg or .mpeg.
The QuickTime Format

The QuickTime format is developed by Apple.

QuickTime is a common format on the Internet, but QuickTime movies cannot be played on a Windows computer without an extra (free) component installed.

Videos stored in the QuickTime format have the extension .mov.
The RealVideo Format

The RealVideo format was developed for the Internet by Real Media.

The format allows streaming of video (on-line video, Internet TV) with low bandwidths. Because of the low bandwidth priority, quality is often reduced.

Videos stored in the RealVideo format have the extension .rm or .ram.
The Shockwave (Flash) Format

The Shockwave format was developed by Macromedia.

The Shockwave format requires an extra component to play. This component comes preinstalled with the latest versions of Netscape and Internet Explorer.

Videos stored in the Shockwave format have the extension .swf.

Multimedia Sound Formats

The MIDI Format

The MIDI (Musical Instrument Digital Interface) is a format for sending music information between electronic music devices like synthesizers and PC sound cards.

The MIDI format was developed in 1982 by the music industry. The MIDI format is very flexible and can be used for everything from very simple to real professional music making.

MIDI files do not contain sampled sound, but a set of digital musical instructions (musical notes) that can be interpreted by your PC's sound card.

The downside of MIDI is that it cannot record sounds (only notes). Or, to put it another way: It cannot store songs, only tunes.

Click here to play The Beatles.

The upside of the MIDI format is that since it contains only instructions (notes), MIDI files can be extremely small. The example above is only 23K in size but it plays for nearly 5 minutes.

The MIDI format is supported by many different software systems over a large range of platforms. MIDI files are supported by all the most popular Internet browsers.

Sounds stored in the MIDI format have the extension .mid or .midi.
The RealAudio Format

The RealAudio format was developed for the Internet by Real Media. The format also supports video.

The format allows streaming of audio (on-line music, Internet radio) with low bandwidths. Because of the low bandwidth priority, quality is often reduced.

Sounds stored in the RealAudio format have the extension .rm or .ram.
The AU Format

The AU format is supported by many different software systems over a large range of platforms.

Sounds stored in the AU format have the extension .au.
The AIFF Format

The AIFF (Audio Interchange File Format) was developed by Apple.

AIFF files are not cross-platform and the format is not supported by all web browsers.

Sounds stored in the AIFF format have the extension .aif or .aiff.
The SND Format

The SND (Sound) was developed by Apple.

SND files are not cross-platform and the format is not supported by all web browsers.

Sounds stored in the SND format have the extension .snd.
The WAVE Format

The WAVE (waveform) format is developed by IBM and Microsoft.

It is supported by all computers running Windows, and by all the most popular web browsers.

Sounds stored in the WAVE format have the extension .wav.
The MP3 Format (MPEG)

MP3 files are actually MPEG files. But the MPEG format was originally developed for video by the Moving Pictures Experts Group. We can say that MP3 files are the sound part of the MPEG video format.

MP3 is one of the most popular sound formats for music recording. The MP3 encoding system combines good compression (small files) with high quality. Expect all your future software systems to support it.

Sounds stored in the MP3 format have the extension .mp3, or .mpga (for MPG Audio).
What Format To Use?

The WAVE format is one of the most popular sound format on the Internet, and it is supported by all popular browsers. If you want recorded sound (music or speech) to be available to all your visitors, you should use the WAVE format.

The MP3 format is the new and upcoming format for recorded music. If your website is about recorded music, the MP3 format is the choice of the future.

MULTIMEDIA....

What is Multimedia?

Multimedia is everything you can hear or see: texts, books, pictures, music, sounds, CDs, videos, DVDs, Records, Films, and more.

Multimedia comes in many different formats. On the Internet you will find many of these elements embedded in web pages, and today's web browsers have support for a number of multimedia formats.

In this tutorial you will learn about different multimedia formats and how to use them in your web pages.
Browser Support

The first Internet browsers had support for text only, and even the text support was limited to a single font in a single color, and little or nothing else.

Then came web browsers with support for colors, fonts and text styles, and the support for pictures was added.

The support for sounds, animations and videos is handled in different ways by different browsers. Some elements can be handled inline, some requires a plug-in and some requires an ActiveX control.

You will learn more about this in the next chapters.
Multimedia Formats

Multimedia elements (like sounds or videos) are stored in media files.

The most common way to discover the media type is to look at the file extension.

When a browser sees the file extensions .htm or .html, it will assume that the file is an HTML page. The .xml extension indicates an XML file, and the .css extension indicates a style sheet.

Picture formats are recognized by extensions like .gif and .jpg.

Multimedia elements also have their own file formats with different extensions.

Saturday, June 14, 2008

BROWSER OPERA

Latest Opera Releases

Opera 9 (for Windows, Mac, Linux, FreeBSD, and Solaris) - Released in June 2006.

Opera 8.5 (for Windows, Mac, and Linux) - Released in September 2005.

Opera 8 (for Windows) - Released in April 2005.
About Opera
Opera Opera started out as a research project in Norway's telecom company, Telenor, in 1994, and branched out into an independent development company named Opera Software ASA in 1995.

Opera Software ASA develops the Opera Web browser and is an industry leader in the development of Web browsers for the desktop and device markets.

The Opera browser (known as "the third browser", after Internet Explorer and Netscape) has received international acclaim from end-users and the industry press for being faster, smaller and more standards-compliant than other browsers.
Is It Free?

Yes, the Opera browser is free! The earlier banner ads and the licensing fee are removed!!
Web Standard Compliant

When you make your Web site work in Opera, you can be certain that it is open and accessible. Simply write your pages in standards-compliant code, and your site will work in all major browsers and for all major platforms and operating systems.

Opera supports all major Web standards currently in use, including CSS 2.1, HTML 4.01, XHTML1.1, HTTP1.1, DOM 2, ECMAScript (JavaScript), PNG, WML 2.0, SVG 1.1 tiny, Unicode, and the Unicode Bidirectional Algorithm.
Opera Features

Opera has automatic Popup Blocking. This is fine for stopping annoying popup ads, but not so good for sites using popup windows in a good way.

Tabbed Browsing is a modern and time saving feature. It makes it possible to view many web pages in one browser window.

Transfers Panel is is Opera's download manager, with quick access to ongoing and recently finished downloads.

Opera's user interface is translated into multiple languages, and the language can be changed on the fly.

Opera has Customizable Toolbars, allowing the users to add and remove items as well as create new toolbars.

By choosing between different Skins, the users can change the look and feel of Opera.

Opera has direct access to Google's "related pages" feature, available from the "Navigation" menu.

Double clicking on a word on a page will pop up a menu that provides options related to the selected text, such as a Web, dictionary or encyclopedia search.

Opera provides Web authors with immediate access to Page Validation, thus encouraging good practices on the Web.

NETSCAPE is dead...

Netscape is Officially Dead

After 10 years of support, on December 28th 2007, AOL announced that the Netscape browser will be taken off life from February 1st 2008.

Source:
http://blog.netscape.com/2007/12/28/end-of-support-for-netscape

"AOL's focus on transitioning to an ad-supported Web business leaves little room for the size of investment needed to get the Netscape browser to a point many of its fans expect it to be." Netscape development director Tom Drapeau wrote.
AOL acquired Netscape in a $4.2 billion deal in 1998. In 2003 the Mozilla Foundation separated from Netscape and AOL with its former parent providing a $2 million dollar parting gift.

Netscape had been based on Mozilla code since Netscape version 6 appeared in 2000.
Netscape Navigator 9

Netscape Navigator 9 (Beta 1) was released in June 2007. It is based on Mozilla Firefox 2.

Some of the new features in Navigator 9:

Mozilla Features
Since Navigator 9 is based on Mozilla, it has all the latest Mozilla features.
URL Correction
Navigator 9 will automatically correct common typos in URLs.
Link Pad
A new sidebar feature that allows you to save links/URLs that you want to visit later without cluttering your bookmarks.
Extension Compatibility
Navigator 9 will let you install extensions that are compatible with Firefox 2.
Sidebar Mini Browser
Bookmarks and links can be open in the sidebar.
Resizeable Textarea
Drag the bottom-right corners of text fields in forms to add more typing space.
Tab History
Opening a link in a new tab will give the new tab the same history as the source tab.
OPML Support
Navigator 9 supports importing and exporting your bookmarks in OPML format.
Combined Stop/Reload button
To save space in your toolbar, the stop and reload buttons are combined.

Netscape 8

Netscape 8.1.2 was released in September 2006.

Netscape 8 allows you to adjust the security level (Java, JavaScript, cookies settings), and also allows you to switch to use Internet Explorer's engine to render pages when necessary.

New features in Netscape 8:

* Site Controls (dual rendering engine)
* Multi-Bar (dynamic toolbar)
* Form fill/passcard
* Live Content
* Improved tabbed browsing
* Adware & Spyware protection
* Dynamic Security Center

Netscape 7

Netscape 7 is based on open source engine (Gecko) and fine-tune of Netscape 6.

Netscape 7 has been reported very stable and fast.
Netscape 6

Netscape 6 was released in November 2000. This version was the first Netscape browser with powerful support for CSS and XML.

Netscape 6 is based on open source engine (Gecko), while Netscape Communicator 4.8 used the engine that was originally released in late 1994.
The Netscape Problem

Netscape's 4.x series of browsers had a poor support for CSS and no support for XML.

It took Netscape nearly three and a half years after the release of 4.0, to produce its next generation browser. This delay has clearly hurt Netscape's possibilities to dominate the browser market.

Our browser statistics are showing that Netscape is losing the browser war.
Older Netscape Versions

Netscape 5.0 - Netscape skipped the version number 5.

Netscape Communicator 4.0 (released in 1997) Too old. Don't use it.

Netscape Navigator 3.0 (released in 1996). Too old. Don't use it.

Netscape Navigator 2.0 (released in 1996). Too old. Don't use it.

Netscape 1.0 (released in 1994). Too old. Don't use it.

BROWSER Internet Explorer...

Internet Explorer 8

Internet Explorer 8 public beta 1 was released March 5th 2008.

Microsoft has annonced that Internet Explorer 8 will interpret web pages according to strict W3C standards by default.

Previously, Microsoft announced that IE 8 would use the "IE7 standard" as default, and that interpreting web pages according to strict W3C standard would be a secondary option. This created strong reactions in the web developer community, as the "IE 7 standard" does not completely conform to W3C.

However, Microsoft have now reversed this decision, and it looks like Internet Explorer 8 will be truly standards-compliant.

IE 8 has full support for CSS 2.1. In addition, it fixes "many cross-browser inconsistencies such as get/set/removeAttribute, default attributes, Attribute object and the < Q > tag.
New features:

Activities provide quick access web services. Users can look up and send information from the Web. On a restaurant web site, for example, the user can click within the page to get maps, news, and information about the restaurant, blog about it, or share it on Facebook.

WebSlices is an RSS-like feature that allows users to subscribe to content directly within a page.
Internet Explorer 7

Internet Explorer 7.0 was released in November 2006.

Internet Explorer 7 provides improved navigation through tabbed browsing, web search from the toolbar, advanced printing, easy discovery, reading and subscription to RSS feeds.

New features:

* Advanced printing (automatically scales a webpage for printing)
* Instant Search box
* Favorites Center
* RSS feeds (automatically detects RSS feeds)
* Tabbed browsing (view multiple sites in a single browser window)
* Quick Tabs
* Tab Groups
* Page zoom

See W3Schools' month by month statistics.
Internet Explorer 6

Internet Explorer 6.0 is the standard browser in Windows XP. It was released in August 2001.

Windows XP is built on Windows 2000 and is the successor to Windows 98, Millennium, and Windows 2000.
Internet Explorer 5

Internet Explorer 5 was the first major browser with XML support.

Version 5.5 (July 2000) for Windows 95, 98, NT 4.0, and Windows 2000. Support for XML/XSL, CSS, printing (print preview) and HTC behaviors.

Version 5.01 (November 1999) Primarily a bug fix for 5.0.

Version 5.0 (March 1999) The first major browser with XML support.
Older Internet Explorer Versions

The oldest versions of Internet Explorer are no longer in use by any majority of users. Web developers will ignore them. Their functionality is outdated.

Version 4.0 (released in 1997) is used by less than 1%. It has respectable CSS and DOM support, but no XML support.

Version 3.0 (released in 1996) is now used by less than 0.1%.

Version 2.0 (released in 1995). It is too old. Nobody uses it.

Version 1.0 (released in 1995). Does anyone remember it?
Internet Explorer for Macintosh

Version 5.1.7 is the latest version of Internet Explorer for Mac OS 8 and 9. It was released in July 2003.

Version 5.2.3 is the latest version of Internet Explorer for Mac OS X. It was released in June 2003.

Note: version 5.2.3 requires special features in Mac OS X. Mac OS 8 and 9 users must download and install version 5.1.7.
Microsoft Internet Explorer Downloads

Download Internet Explorer for free at: http://www.microsoft.com/windows/products/winfamily/ie/default.mspx.

Download the latest security updates and bug fixes at: http://www.microsoft.com/windows/downloads/ie/getitnow.mspx

Internet Explorer for Mac is no longer available for download!

In June 2003, the Microsoft Macintosh Business Unit announced that Internet Explorer for Mac would undergo no further development, and support would cease in 2005. Microsoft ended support for Internet Explorer for Mac on December 31st, 2005. Accordingly, as of January 31st, 2006, Internet Explorer for the Mac is no longer available for download from Microsoft. It is recommended that Macintosh users migrate to more recent web browsing technologies such as Apple's Safari.

NET mozilla...

What is Mozilla?
Mozilla Mozilla is not a web browser.

Mozilla is a framework for building web applications using web standards like CSS, XML, RDF.

Mozilla code is used in Netscape 6 and 7, and in other web browsers such as Firefox and Camino, chat clients, news clients, email clients, games, and other types of web applications for Windows, Linux, and Mac.

Mozilla is an open-source web development project developing the program code used in the Mozilla Application Suite (also known as SeaMonkey).

The Mozilla Application Suite is a complete set of web applications (browser, email client, news client, chat client and more).

Browsers based on Mozilla code (Mozilla, Firefox, & Camino) is the second largest browser family on the Internet today, representing about 30% of the Internet community. Mozilla browsers are known to have very good web standards support.
The Mozilla Project

The Mozilla Project was created to continue developing Netscape as an open source project.

In November 1998 AOL (America Online) purchased Netscape.

The development of the core engine for Netscape was moved to an open source project called "The Mozilla Project".

The project was renamed SeaMonkey after April 2006 with the Mozilla Foundations main intention of phasing out the Mozilla suite and shifting it's main focus to the Firefox/Thunderbird/SeaMonkey projects
The Mozilla Foundation

The Mozilla Foundation was created in July 2003 when AOL laid off the employees involved in the Mozilla open-source browser team.
Mozilla Foundation's Roadmap

The Mozilla project decided to make a new roadmap for the development. Some of the points in the new roadmap is listed below:

* Focus on standalone applications (the FireFox browser, the Thunderbird mail/news application, and standalone composer)
* Make Firefox and Thunderbird the premier products of Mozilla
* Maintain the SeaMonkey (current Mozilla browser) application suite for enterprises and organizations with large Mozilla deployments
* Maintain the Mozilla 1.4 branch as the "distributor/vendor" branch used by organizations with year-long lead times
* Fix crucial Gecko layout architecture bugs. All Mozilla applications benefit from such Gecko improvements
* Prefer quality over quantity. Do less, but better!

Products of Mozilla

* Mozilla - the application suite
* Firefox - a standalone browser
* Thunderbird - an email and newsgroup client
* Camino - a web browser for Mac
* Composer - a web page editor

Versions for Windows, Linux, and Mac can be downloaded from:

http://www.mozilla.org
Confusing Mozilla Names

The very first Netscape browser had a code engine called Mozilla. Netscape 1.0 was powered with a code engine called Mozilla 1.0. Netscape 2.0 used Mozilla 2.0, Netscape 3.0 used Mozilla 3.0, and Netscape 4.0 used Mozilla 4.0.

In 1998 the source code of Netscape 4 was made public - and the development of Netscape 5 was made an open source project.

The open source project for creating Netscape 5 was called "The Mozilla Project". Strangely enough, the code engine for the Mozilla Project was called Gecko.

Unfortunately it took Netscape more than three and a half years after the release of 4.0, to produce its next generation browser. This delay destroyed Netscape's possibilities to remain a credible alternative to Microsoft's Internet Explorer. Microsoft released IE 5.0 just after the Mozilla project had started, and was ready with IE 6.0 before Netscape managed to release a workable browser.

Netscape 6.0 based on Gecko M18 (Milestone 18) was released in November 2000.

After the release of Netscape 6.0, the Mozilla Project started to work on Netscape 7 based on an engine called Mozilla 1.0 !!.

Netscape 6 and 7 are built on Mozilla and Netscape and Mozilla are nearly an identical suite of applications.

The current version of Netscape 7 claims to have a code engine called Gecko 1.0 !!

At the moment the Mozilla Project is developing a new web browser called Firefox. Firefox was previously called Mozilla Firebird (which was previously called Phoenix, which claimed to be a new version of Mozilla).

Confused? I am.

The confusing name changes must have something to do with legal issues (I think).
Mozilla Releases

The Mozilla Foundation has released the following versions of Mozilla:

Mozilla 1.8 Alpha 5 November 22, 2004

Mozilla 1.8 Alpha 4 September 28, 2004

Mozilla 1.8 Alpha 3 August 18, 2004

Mozilla 1.8 Alpha 2 July 14, 2004

Mozilla 1.8 Alpha 1 May 20, 2004

Mozilla 1.7.3 September 13, 2004

Mozilla 1.7.2 August 4, 2004

Mozilla 1.7.1 July 8, 2004

Mozilla 1.7 June 17, 2004

Mozilla 1.7 RC3 June 8, 2004

Mozilla 1.7 RC2 May 17, 2004

Mozilla 1.7 RC1 April 21, 2004

Mozilla 1.7 Beta March 18, 2004

Mozilla 1.7 Alpha February 23, 2004

Mozilla 1.6 January 15, 2004

Mozilla 1.6 Beta December 9, 2003

Mozilla 1.6 Alpha October 31, 2003

Mozilla 1.5.1 November 26, 2003

Mozilla 1.5 October 15, 2003

Mozilla 1.5 RC2 September 26, 2003

Mozilla 1.5 RC1 September 17, 2003

Mozilla 1.5 Beta August 27, 2003

Mozilla 1.5 Alpha July 22, 2003

Mozilla 1.4.1 October 10, 2003

Mozilla 1.4 June 30, 2003

Source: http://www.mozilla.org/releases/

WEB statistics..

Web Statistics and Trends

Statistics are important information. From the statistics below, you can see that Internet Explorer is the most common browser. However, FireFox has become quite popular as well.
Browser Statistics Month by Month
2008 IE7 IE6 IE5 Fx Moz S O
April 24.9% 28.9% 1.0% 39.1% 1.0% 2.2% 1.4%
March 23.3% 29.5% 1.1% 37.0% 1.1% 2.1% 1.4%
February 22.7% 30.7% 1.3% 36.5% 1.2% 2.0% 1.4%
January 21.2% 32.0% 1.5% 36.4% 1.3% 1.9% 1.4%

2007 IE7 IE6 IE5 Fx Moz S O
December 21.0% 33.2% 1.7% 36.3% 1.4% 1.7% 1.4%
November 20.8% 33.6% 1.6% 36.3% 1.2% 1.8% 1.6%
October 20.7% 34.5% 1.5% 36.0% 1.3% 1.7% 1.6%
September 20.8% 34.9% 1.5% 35.4% 1.2% 1.6% 1.5%
August 20.5% 35.7% 1.5% 34.9% 1.3% 1.5% 1.7%
July 20.1% 36.9% 1.5% 34.5% 1.4% 1.5% 1.9%
June 19.7% 37.3% 1.5% 34.0% 1.4% 1.5% 1.8%
May 19.2% 38.1% 1.6% 33.7% 1.3% 1.5% 1.7%
April 19.1% 38.4% 1.7% 32.9% 1.3% 1.5% 1.6%
March 18.0% 38.7% 2.0% 31.8% 1.3% 1.6% 1.6%
February 16.4% 39.8% 2.5% 31.2% 1.4% 1.7% 1.5%
January 13.3% 42.3% 3.0% 31.0% 1.5% 1.7% 1.5%

2006 IE7 IE6 IE5 Fx Moz N7/8 O
November 7.1% 49.9% 3.6% 29.9% 2.5% 0.2% 1.5%
September 2.5% 55.6% 4.0% 27.3% 2.3% 0.4% 1.6%
July 1.9% 56.3% 4.2% 25.5% 2.3% 0.4% 1.4%
May 1.1% 57.4% 4.5% 25.7% 2.3% 0.3% 1.5%
March 0.6% 58.8% 5.3% 24.5% 2.4% 0.5% 1.5%
January 0.2% 60.3% 5.5% 25.0% 3.1% 0.5% 1.6%

2005 IE6 IE5 Fx Moz N7 O8 O7
November 62.7% 6.2% 23.6% 2.8% 0.4% 1.3% 0.2%
September 69.8% 5.7% 18.0% 2.5% 0.4% 1.0% 0.2%
July 67.9% 5.9% 19.8% 2.6% 0.5% 0.8% 0.4%
May 64.8% 6.8% 21.0% 3.1% 0.7% 0.7% 0.6%
March 63.6% 8.9% 18.9% 3.3% 1.0% 0.3% 1.6%
January 64.8% 9.7% 16.6% 3.4% 1.1% 1.9%

2004 IE6 IE5 Moz N3 N7 N4 O7
November 66.0% 10.2% 16.5% 0.2% 1.2% 0.3% 1.6%
September 67.8% 11.2% 13.7% 0.3% 1.4% 0.3% 1.7%
July 67.2% 13.2% 12.6% 0.4% 1.4% 0.4% 1.6%
May 68.1% 13.8% 9.5% 0.6% 1.4% 0.4% 1.6%
March 68.2% 14.6% 7.9% 0.8% 1.4% 0.6% 1.4%
January 68.9% 15.8% 5.5% 0.4% 1.5% 0.5% 1.5%

2003 IE6 IE5 Moz N3 N7 N4 O7
November 71.2% 13.7% 7.2% 0.5% 1.6% 0.5% 1.9%
September 69.7% 16.9% 6.2% 0.6% 1.5% 0.6% 1.8%
July 66.9% 20.3% 5.7% 0.6% 1.5% 0.6% 1.7%
May 65.0% 22.7% 4.6% 1.0% 1.4% 0.9% 1.4%
March 63.4% 24.6% 4.2% 0.9% 1.4% 1.1% 1.2%
January 55.3% 29.3% 4.0% 1.2% 1.1% 1.7%

2002 IE6 IE5 AOL N3 N5 N4 IE4
November 53.5% 29.9% 5.2% 1.1% 4.9% 2.0%
September 49.1% 34.4% 4.5% 1.3% 4.5% 2.2%
July 44.4% 40.1% 3.5% 1.2% 3.5% 2.6% 0.5%
May 40.7% 46.0% 2.8% 1.2% 2.7% 3.4% 0.7%
March 36.7% 49.4% 3.0% 1.2% 2.4% 4.1% 0.7%
January 30.1% 55.7% 2.8% 1.3% 2.2% 4.4% 1.0%


IE Internet Explorer
Fx Firefox (identified as Mozilla before 2005)
Moz The Mozilla Suite (Gecko, Netscape)
S Safari (and Konqueror. Both identified as Mozilla before 2007)
O Opera
N Netscape (identified as Mozilla after 2006)
AOL America Online (based on both Internet Explorer and Mozilla)

Browsers that count for less than 0.5% are not listed.

W3Schools is a website for people with an interest for web technologies. These people are more interested in using alternative browsers than the average user. The average user tends to use Internet Explorer, since it comes preinstalled with Windows. Most do not seek out other browsers.

These facts indicate that the browser figures above are not 100% realistic. Other web sites have statistics showing that Internet Explorer is used by at least 80% of the users.

Anyway, our data, collected from W3Schools' log-files, over a five year period, clearly shows the long and medium-term trends.
JavaScript Statistics

There are no absolute trends about the use of JavaScript. Some users have scripting turned off. Some browsers don't support scripting:
Date JavaScript On JavaScript Off
January 2008 95% 5%
January 2007 94% 6%
January 2006 90% 10%
January 2005 89% 11%
January 2004 92% 8%
January 2003 89% 11%
January 2002 88% 12%
January 2001 81% 19%
January 2000 80% 20%

WEB awards

How to win an award

The best way to win an award is of course to have an excellent Web Site, but there are some pointers that can help you. There are award giving Web Sites where you can submit your URL, and they review your Site and decide if they will give you their award or not.
Award Sites
TechSighthings TechSightings gives you weekly reviews of the Best High-Tech Sights on the Net. They review pages in different categories. If your site wins, you will receive a prize that you can add to your page. You can suggest your site or another site via an input form.

DailyAward The DailyWebSite introduces websites that they find very useful and interesting. You can suggest your site or another site via an input form.

WebBuilderMag WebBuilder reviews Web Sites which you send them via e-mail. They also rate the award giving Web Site.

WebbyAward WebbyAwards is the Internet's Oscar Prize. The awards are given once each year, in several categories. Each category has 2 winners, The Webby Award given by the judges, and the People's Voice award, given by the people. You can suggest your site as a nominee for the next year's award.

WebAward2000 The GoldenWebAward Presented by The International Association of Web Masters and Designers. In Recognition for creativity, integrity and excellence. The Golden Web Award is a free service, presented to those sites whose web design and content have achieved levels of excellence deserving of recognition. You can suggest your site or another site via an input form.

MarketMe The Webmaster Award is a special Internet award given only to those elite webmasters responsible for creating those websites that keep us up so late night after night. You can suggest your site or another site via an input form.

SurfersChoice The Surfers Choice is a Best of the Web Portal specializing in content rich, high quality Websites. The goal is to provide you with a special service that will promote your site in a small, manageable database where surfers can find the best and most relevant sites. You can suggest your site via an input form.

GoldenCrane The Golden Crane Creativity Award (GCCA) is awarded to sites providing free instructional information in arts, crafts, music, and other creative activities. If you would like to nominate a site for this award, you can add the URL to their directory for review.

WEB search engines...

Search Engines that will accept your URL

* Google
http://www.google.com/addurl.html
* Yahoo!
http://docs.yahoo.com/info/suggest/
* Altavista
http://www.altavista.com/addurl/
* AllTheWeb
http://www.alltheweb.com/add_url.php
* Dmoz
http://www.dmoz.org/help/submit.html
* Webcrawler
http://www.webcrawler.com
* Dogpile
http://www.dogpile.com
* MetaCrawler
http://www.metacrawler.com
* LookSeek
http://www.lookseek.com

WEB security..

YOUR IP ADDRESS IS PUBLIC

Accessing the Internet is a security risk.

When you are connected to the Internet, an IP address is used to identify your PC. If you don't protect yourself, this IP address can be used to access your computer from the outside world.

A fixed IP address is a larger security risk.

If you're using a modem with a dial-up connection, you will get a new IP address every time you connect to Internet, but if you have a fixed Internet connection (cable, ADSL, fixed line), your IP address will never change.

If you have a fixed IP address, you give potential Internet crackers all the time they need to search for entrances to your computer, and to store and share (with other crackers) information they might find about your unprotected private data.
Your Network Shares

Personal computers are often connected to a shared network. Personal computers in large companies are connected to large corporate networks. Personal computers in small companies are connected to a small local network, and computers in private homes often share a network between family members.

Most often networks are used to share resources like printers, files and disk storage.

When you are connected to the Internet, your shared resources can be accessed by the rest of the world.
A Common Windows Security Problem

Unfortunately, many Microsoft Windows users are unaware of a common security leak in their network settings.

This is a common setup for network computers in Microsoft Windows:

* Client for Microsoft Networks
* File and Printer Sharing for Microsoft Networks
* NetBEUI Protocol
* Internet Protocol TCP/IP

If your setup allows NetBIOS over TCP/IP, you have a security problem:

* Your files can be shared all over the Internet
* Your logon-name, computer-name, and workgroup-name are visible to others.

If your setup allows File and Printer Sharing over TCP/IP, you also have a problem:

* Your files can be shared all over the Internet

Computers that are not connected to any network can also have dangerous network settings because the network settings were changed when Internet was installed.
Solving the Problem

For Windows 2000 users:

You can solve your security problem by disabling NetBIOS over TCP/IP:

* Open Windows Explorer
* Right-click on My Network Places
* Select: Properties
* Right-click on Local Area Network
* Select: Properties
* Select: Internet Protocol TCP/IP
* Click on Properties
* Click on Advanced
* Select the WINS tab
* Select Disable NetBIOS over TCP/IP
* Click OK

WEB standards..

Why Web Standards?

Web developers are often struggling with time-consuming double-coding to solve problems with different browsers versions. This situation will get much worse when new hardware (like mobile telephones and other handheld devices) and new software (like micro-browsers) start browsing the Web.

To make the Web a better place, for both developers and end-users, it is of paramount importance that both browser vendors and site developers follow standards when they develop new applications.

With its tremendous growth, the Web needs standards to realize its full potential. Web standards ensure that everyone has access to the same information. Future use of the Web, including applications that we only dream of today, will not be possible without world wide standards.

Web standards also make site development faster and more enjoyable. Future Web sites will have to be coded according to standards to shorten both development and maintenance time. Developers should not have to struggle with several versions of code to accomplish the same result.
Other Considerations

When Web developers follow Web standards, web development teamwork is simplified, since it is easier for the developers to understand each other's coding.

Some developers think that standards are the same as restrictions, and that taking advantage of nice browser-specific features will add credit to their work. But future adjustments to these Web pages will become more and more difficult as the variety of access methods increases. Following standards is your first step to solve this problem. Using only Web standards will help you to ensure that all browsers, old and new, will display your site properly, without frequent and time-consuming rewrites.

Standardization can increase the access to your site. Does it make sense to limit your audience to only those with a particular browser?

Standard Web documents are easier for search engines to access, and easier to index more accurately.

Standard Web documents are easier to convert to other formats.

Standard Web documents are easier to access with program code (like JavaScript and the DOM).

Want to save yourself a lot of time? Make a habit of validating your pages with a validation service. Validation keeps your documents up to the standards and free of nasty errors.
Accessibility

Accessibility is an important part of the HTML standard.

Standards make it easier for people with disabilities to use the Web. Blind people can use computers that read Web pages for them. People with poor sight can rearrange and magnify standard Web pages. Simple Web standards like HTML 4 and CSS, will make your Web pages much easier to understand by special devices like voice browsers, or other unusual output devices.
The World Wide Web Consortium

The World Wide Web Consortium (W3C), founded in 1994, is an international consortium dedicated to "lead the Web to its full potential".

As developers, especially when creating educational Web sites, we can help them turn this dream into reality.

WEB users

What Monitors Do They Have?

Remember that not everyone on the Web has the same monitor as you have. If you design your Web pages to be displayed on a monitor with a 1024x768 resolution, some of your visitors with lower resolution monitors (like 640x480) might have problems reading your pages.

Some users still have low resolution 640x480 monitors, but the trend is moving towards 800x600 as the low resolution standard. This Web site is designed to be best viewed on 800x600 or better resolution.

If you are one of those developers with a sophisticated monitor (1600x1200?), make sure you test the display of your Web pages on different monitors with lower resolutions.

One wise thing to do when designing the layout of Web pages is to let a section of each page be of variable size to fit the size of a large or small resolution monitor.

Take a look at our browser display statistics to see the trends in monitor development.
What Browsers Do They Use?

Both of the two major Internet browsers (Netscape and Microsoft) have their own specialties and quirks that you must consider when designing your Web pages.

If you are serious about your Web site, don't forget to test every page with different types of browsers.

The most popular browsers today are Microsoft Internet Explorer and Mozilla Firefox.

Additionally, some of your visitors might use text only browsers, such as Lynx, or they might visit your site from an online service like AOL, CompuServe or Prodigy. Some of these browsers might not display your Web pages as well as you think.

One wise thing to do when designing Web pages is to use strict, formal and correct HTML (or XHTML). Strict and correct coding will always help a browser to display your pages correctly.

Take a look at our browser statistics to see the trends in browser development.
What Plug-Ins Do They Have?

Some elements in your Web pages, like sound and video clips or other multimedia content, might require the use of separate programs (helper applications or plug-ins).

Don't use such elements in your Web pages unless you are sure that your visitors have access to the software needed to view them.

WEB Building

Every Web developer has to know the building blocks of the Web:
Web Developer

* HTML 4.01
* The use of CSS (style sheets)
* XHTML
* XML and XSLT
* Client side scripting
* Server side scripting
* Managing data with SQL
* The future of the Web

HTML 4.01

HTML is the language of the Web, and every Web developer should have a basic understanding of it.

HTML 4.01 is an important Web standard. and very different from HTML 3.2.

When tags like and color attributes were added to HTML 3.2, it started a developer's nightmare. Development of web sites where font information must be added to every single Web page is a long and expensive pain.

With HTML 4.01 all formatting can be moved out of the HTML document and into a separate style sheet.

HTML 4.01 is also important because XHTML 1.0 (the latest HTML standard) is HTML 4.01 "reformulated" as an XML application. Using HTML 4.01 in your pages makes the future upgrade from HTML to XHTML a very simple process.

Make sure you use the latest HTML 4.01 standard.

Study our Complete HTML 4.01 reference.
Cascading Style Sheets (CSS)

Styles define how HTML elements are displayed, just like the font tag in HTML 3.2. Styles are normally saved in files external to HTML documents. External style sheets enable you to change the appearance and layout of all the pages in your Web, just by editing a single CSS document. If you have ever tried changing something like the font or color of all the headings in all your Web pages, you will understand how CSS can save you a lot of work.

Make sure you study our CSS tutorial.
XHTML - The Future of HTML

XHTML stands for Extensible HyperText Markup Language.

XHTML 1.0 is now the latest HTML standard from W3C. It became an official Recommendation January 26, 2000. A W3C Recommendation means that the specification is stable and that the specification is now a Web standard.

XHTML is a reformulation of HTML 4.01 in XML and can be put to immediate use with existing browsers by following a few simple guidelines.

To prepare for the future: Read how this site was converted to XHTML.
XML - A Tool for Describing Data

The Extensible Markup Language (XML) is NOT a replacement for HTML. In future Web development, XML will be used to describe and carry the data, while HTML will be used to display the data.

Our best description of XML is as a cross-platform, software- and hardware-independent tool for storing and transmitting information.

We believe that XML is as important to the Web as HTML was to the foundation of the Web and that XML will be the most common tool for all data manipulation and data transmission.

Make sure you study our XML tutorial.
XSLT - A Tool for Transforming Data

XSLT (Extensible Stylesheet Language Transformations) is a language for transforming XML.

Future Web sites will have to deliver data in different formats, to different browsers, and to other Web servers. To transform XML data into different formats, XSLT is the new W3C standard.

XSLT can transform an XML file into a format that is recognizable to a browser. One such format is HTML. Another format is WML - the mark-up language used in many handheld devices.

XSLT can also add elements, remove, rearrange and sort elements, test and make decisions about which elements to display, and a lot more.

Make sure you study our XSLT tutorial.
Client-Side Scripting

Client-side scripting is about "programming" the behavior of an Internet browser. To be able to deliver more dynamic web site content, you should teach yourself JavaScript:

* JavaScript gives HTML designers a programming tool - HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages.
* JavaScript can put dynamic text into an HTML page - A JavaScript statement like this: document.write("

" + name + "

") can write a variable text into an HTML page.
* JavaScript can react to events - A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user clicks on an HTML element.
* JavaScript can read and write HTML elements - A JavaScript can read and change the content of an HTML element.
* JavaScript can be used to validate data - A JavaScript can be used to validate form data before it is submitted to a server, this will save the server from extra processing.

Make sure you study our JavaScript Tutorial.
Server-Side Scripting

Server-side scripting is about "programming" an Internet server. To be able to deliver more dynamic web site content, you should teach yourself server-side scripting. With server-side scripting, you can:

* Dynamically edit, change, or add any content of a Web page
* Respond to user queries or data submitted from HTML forms
* Access any data or databases and return the results to a browser
* Access any files or XML data and return the results to a browser
* Transform XML data to HTML data and return the results to a browser
* Customize a Web page to make it more useful for individual users
* Provide security and access control to different Web pages
* Tailor your output to different types of browsers
* Minimize the network traffic

At W3Schools we demonstrate server-side scripting by using Active Server Pages (ASP) and PHP: Hypertext Preprocessor (PHP).

.NET

Windows.NET

Today, Windows 2000 and Windows XP form the backbone of .NET.

In the future, the .NET infrastructure will be integrated into all Microsoft's operating systems, desktop and server products.

Windows.NET is the next generation Windows. It will provide support for all the .NET building blocks and .NET digital media. Windows.NET will be self-supporting with updates via Internet as users need them.
Office.NET

A new version of Microsoft Office - Office.NET - will have a new .NET architecture based on Internet clients and Web Services.

With Office.NET, browsing, communication, document handling and authoring will be integrated within a XML-based environment which allow users to store their documents on the Internet.
ASP.NET

ASP.NET is the latest version of ASP. It includes Web Services to link applications, services and devices using HTTP, HTML, XML and SOAP.

New in ASP.NET:

* New Language Support
* Programmable Controls
* Event Driven Programming
* XML Based Components
* User Authentication
* User Accounts and Roles
* High Scalability
* Compiled Code
* Easy Configuration
* Easy Deployment
* Not ASP Compatible
* Includes ADO.NET

You can read more about ASP.NET and ADO.NET in our ASP.NET Tutorial.
Visual Studio.NET

The latest version of Visual Studio - Visual Studio.NET - incorporates ASP.NET, ADO.NET, Web Services, Web Forms, and language innovations for Visual Basic. The development tools have deep XML support, an XML-based programming model and new object-oriented programming capabilities.
Visual Basic.NET

Visual Basic.NET has added language enhancements, making it a full object-oriented programming language.
SQL Server 2000

SQL Server 2000 is a fully web-enabled database.

SQL Server 2000 has strong support for XML and HTTP which are two of the main infrastructure technologies for .NET.

Some of the most important new SQL Server features are direct access to the database from a browser, query of relational data with results returned as XML, as well as storage of XML in relational formats.
Internet Information Services 6.0

IIS 6.0 has strong support for more programming to take place on the server, to allow the new Web Applications to run in any browser on any platform.

Friday, June 13, 2008

AJAX XML

AJAX Database as XML Example

In the AJAX example below we will demonstrate how a web page can fetch information from a MySQL database, convert it to an XML document, and use it to display information in several different places.

This example my seem a lot like the "PHP AJAX Database" example in the last chapter, however there is a big difference: in this example we get the data from the PHP page as XML using the responseXML function.

Receiving the response as an XML document allows us to update this page several places, instead of just receiving a PHP output and displaying it.

In this example we will update several elements with the information we receive from the database.
Select a Name in the Box Below
Select a User:


This example consists of four elements:

* a MySQL database
* a simple HTML form
* a JavaScript
* a PHP page

The Database

The database we will be using in this example looks like this:
id FirstName LastName Age Hometown Job
1 Peter Griffin 41 Quahog Brewery
2 Lois Griffin 40 Newport Piano Teacher
3 Joseph Swanson 39 Quahog Police Officer
4 Glenn Quagmire 41 Quahog Pilot

The HTML Form

The example above contains a simple HTML form and a link to a JavaScript:








Select a User:




 













Example Explained - The HTML Form

* The HTML form is a drop down box called "users" with names and the "id" from the database as option values.
* Below the form there are several different elements which are used to as placeholders for the different values we will retrive.
* When the user selects data, a function called "showUser()" is executed. The execution of the function is triggered by the "onchange" event.

In other words: Each time the user changes the value in the drop down box, the function showUser() is called and outputs the result in the specified elements.
The JavaScript

This is the JavaScript code stored in the file "responsexml.js":

var xmlHttp

function showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="responsexml.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
xmlDoc=xmlHttp.responseXML;
document.getElementById("firstname").innerHTML=
xmlDoc.getElementsByTagName("firstname")[0].childNodes[0].nodeValue;
document.getElementById("lastname").innerHTML=
xmlDoc.getElementsByTagName("lastname")[0].childNodes[0].nodeValue;
document.getElementById("job").innerHTML=
xmlDoc.getElementsByTagName("job")[0].childNodes[0].nodeValue;
document.getElementById("age_text").innerHTML="Age: ";
document.getElementById("age").innerHTML=
xmlDoc.getElementsByTagName("age")[0].childNodes[0].nodeValue;
document.getElementById("hometown_text").innerHTML="
From: ";
document.getElementById("hometown").innerHTML=
xmlDoc.getElementsByTagName("hometown")[0].childNodes[0].nodeValue;
}
}

function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}

Example Explained

The showUser() and GetXmlHttpObject functions are the same as in the PHP AJAX Database chapter, you can go to there for an explanation of those.

The stateChanged() Function

If an item in the drop down box is selected the function executes the following:

1. Defines the "xmlDoc" variable as an xml document using the responseXML function
2. Retrieves data from the xml documents and places them in the correct elements

The PHP Page

The server page called by the JavaScript, is a simple PHP file called "responsexml.php".

The page is written in PHP and uses a MySQL databse.

The code runs a SQL query against a database and returns the result as an XML document:

header('Content-Type: text/xml');
header("Cache-Control: no-cache, must-revalidate");
//A date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

$q=$_GET["q"];

$con = mysql_connect('localhost', 'peter', 'abc123');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("ajax_demo", $con);

$sql="SELECT * FROM user WHERE id = ".$q."";

$result = mysql_query($sql);

echo '
';
while($row = mysql_fetch_array($result))
{
echo "" . $row['FirstName'] . "";
echo "" . $row['LastName'] . "";
echo "" . $row['Age'] . "";
echo "" . $row['Hometown'] . "";
echo "" . $row['Job'] . "";
}
echo "
";

mysql_close($con);
?>

Example Explained

When the query is sent from the JavaScript to the PHP page the following happens:

1. The content-type of the PHP document is set to be "text/xml"
2. The PHP document is set to "no-cache" to prevent caching
3. The $q variable is set to be the data sent from the html page
4. PHP opens a connection to a MySQL server
5. The "user" with the specified id is found
6. The data is outputted as an xml document

AJAX MYSQL database

AJAX Database Example

In the AJAX example below we will demonstrate how a web page can fetch information from a MySQL database using AJAX technology.
Select a Name in the Box Below
Select a User:

User info will be listed here.

This example consists of four elements:

* a MySQL database
* a simple HTML form
* a JavaScript
* a PHP page

The Database

The database we will be using in this example looks like this:
id FirstName LastName Age Hometown Job
1 Peter Griffin 41 Quahog Brewery
2 Lois Griffin 40 Newport Piano Teacher
3 Joseph Swanson 39 Quahog Police Officer
4 Glenn Quagmire 41 Quahog Pilot

The HTML Form

The example above contains a simple HTML form and a link to a JavaScript:








Select a User:




User info will be listed here.






Example Explained - The HTML Form

As you can see it is just a simple HTML form with a drop down box called "users" with names and the "id" from the database as option values.

The paragraph below the form contains a div called "txtHint". The div is used as a placeholder for info retrieved from the web server.

When the user selects data, a function called "showUser()" is executed. The execution of the function is triggered by the "onchange" event.

In other words: Each time the user changes the value in the drop down box, the function showUser() is called.
The JavaScript

This is the JavaScript code stored in the file "selectuser.js":

var xmlHttp

function showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getuser.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

Example Explained

The stateChanged() and GetXmlHttpObject functions are the same as in the PHP AJAX Suggest chapter, you can go to there for an explanation of those.

The showUser() Function

If an item in the drop down box is selected the function executes the following:

1. Calls on the GetXmlHttpObject function to create an XMLHTTP object
2. Defines the url (filename) to send to the server
3. Adds a parameter (q) to the url with the content of the dropdown box
4. Adds a random number to prevent the server from using a cached file
5. Call stateChanged when a change is triggered
6. Opens the XMLHTTP object with the given url.
7. Sends an HTTP request to the server

The PHP Page

The server page called by the JavaScript, is a simple PHP file called "getuser.php".

The page is written in PHP and uses a MySQL databse.

The code runs a SQL query against a database and returns the result as an HTML table:

$q=$_GET["q"];

$con = mysql_connect('localhost', 'peter', 'abc123');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("ajax_demo", $con);

$sql="SELECT * FROM user WHERE id = '".$q."'";

$result = mysql_query($sql);

echo "






";

while($row = mysql_fetch_array($result))
{
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
}
echo "
Firstname Lastname Age Hometown Job
" . $row['FirstName'] . "" . $row['LastName'] . "" . $row['Age'] . "" . $row['Hometown'] . "" . $row['Job'] . "
";

mysql_close($con);
?>

Example Explained

When the query is sent from the JavaScript to the PHP page the following happens:

1. PHP opens a connection to a MySQL server
2. The "user" with the specified name is found
3. A table is created and the data is inserted and sent to the "txtHint" placeholder

PHP XML

What is XML?

XML is used to describe data and to focus on what data is. An XML file describes the structure of the data.

In XML, no tags are predefined. You must define your own tags.

If you want to learn more about XML, please visit our XML tutorial.
What is Expat?

To read and update - create and manipulate - an XML document, you will need an XML parser.

There are two basic types of XML parsers:

* Tree-based parser: This parser transforms an XML document into a tree structure. It analyzes the whole document, and provides access to the tree elements. e.g. the Document Object Model (DOM)
* Event-based parser: Views an XML document as a series of events. When a specific event occurs, it calls a function to handle it

The Expat parser is an event-based parser.

Event-based parsers focus on the content of the XML documents, not their structure. Because of this, event-based parsers can access data faster than tree-based parsers.

Look at the following XML fraction:

Jani

An event-based parser reports the XML above as a series of three events:

* Start element: from
* Start CDATA section, value: Jani
* Close element: from

The XML example above contains well-formed XML. However, the example is not valid XML, because there is no Document Type Definition (DTD) associated with it.

However, this makes no difference when using the Expat parser. Expat is a non-validating parser, and ignores any DTDs.

As an event-based, non-validating XML parser, Expat is fast and small, and a perfect match for PHP web applications.

Note: XML documents must be well-formed or Expat will generate an error.
Installation

The XML Expat parser functions are part of the PHP core. There is no installation needed to use these functions.
An XML File

The XML file below will be used in our example:



Tove
Jani
Reminder
Don't forget me this weekend!

PHP error handling...

PHP Error Handling

When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks.

This tutorial contains some of the most common error checking methods in PHP.

We will show different error handling methods:

* Simple "die()" statements
* Custom errors and error triggers
* Error reporting

PHP email....

The PHP mail() Function

The PHP mail() function is used to send emails from inside a script.

Syntax

mail(to,subject,message,headers,parameters)


Parameter Description
to Required. Specifies the receiver / receivers of the email
subject Required. Specifies the subject of the email. Note: This parameter cannot contain any newline characters
message Required. Defines the message to be sent. Each line should be separated with a LF (\n). Lines should not exceed 70 characters
headers Optional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n)
parameters Optional. Specifies an additional parameter to the sendmail program

Note: For the mail functions to be available, PHP requires an installed and working email system. The program to be used is defined by the configuration settings in the php.ini file. Read more in our PHP Mail reference.
PHP Simple E-Mail

The simplest way to send an email with PHP is to send a text email.

In the example below we first declare the variables ($to, $subject, $message, $from, $headers), then we use the variables in the mail() function to send an e-mail:


$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

?>


PHP Mail Form

With PHP, you can create a feedback-form on your website. The example below sends a text message to a specified e-mail address:




if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail( "someone@example.com", "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "

Email:

Subject:

Message:




";
}
?>





This is how the example above works:

* First, check if the email input field is filled out
* If it is not set (like when the page is first visited); output the HTML form
* If it is set (after the form is filled out); send the email from the form
* When submit is pressed after the form is filled out, the page reloads, sees that the email input is set, and sends the email

Note: This is the simplest way to send e-mail, but it is not secure. In the next chapter of this tutorial you can read more about vulnerabilities in e-mail scripts, and how to validate user input to make it more secure.

PHP cookies.....

What is a Cookie?

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.
How to Create a Cookie?

The setcookie() function is used to set a cookie.

Note: The setcookie() function must appear BEFORE the tag.
Syntax

setcookie(name, value, expire, path, domain);

Example

In the example below, we will create a cookie named "user" and assign the value "Alex Porter" to it. We also specify that the cookie should expire after one hour:

setcookie("user", "Alex Porter", time()+3600);
?>







Note: The value of the cookie is automatically URLencoded when sending the cookie, and automatically decoded when received (to prevent URLencoding, use setrawcookie() instead).
How to Retrieve a Cookie Value?

The PHP $_COOKIE variable is used to retrieve a cookie value.

In the example below, we retrieve the value of the cookie named "user" and display it on a page:

// Print a cookie
echo $_COOKIE["user"];

// A way to view all cookies
print_r($_COOKIE);
?>

In the following example we use the isset() function to find out if a cookie has been set:




if (isset($_COOKIE["user"]))
echo "Welcome " . $_COOKIE["user"] . "!
";
else
echo "Welcome guest!
";
?>





How to Delete a Cookie?

When deleting a cookie you should assure that the expiration date is in the past.

Delete example:

// set the expiration date to one hour ago
setcookie("user", "", time()-3600);
?>


What if a Browser Does NOT Support Cookies?

If your application deals with browsers that do not support cookies, you will have to use other methods to pass information from one page to another in your application. One method is to pass the data through forms (forms and user input are described earlier in this tutorial).

The form below passes the user input to "welcome.php" when the user clicks on the "Submit" button:





Name:
Age:






Retrieve the values in the "welcome.php" file like this:




Welcome .

You are years old.


PHP files....

Opening a File

The fopen() function is used to open files in PHP.

The first parameter of this function contains the name of the file to be opened and the second parameter specifies in which mode the file should be opened:




$file=fopen("welcome.txt","r");
?>




The file may be opened in one of the following modes:
Modes Description
r Read only. Starts at the beginning of the file
r+ Read/Write. Starts at the beginning of the file
w Write only. Opens and clears the contents of file; or creates a new file if it doesn't exist
w+ Read/Write. Opens and clears the contents of file; or creates a new file if it doesn't exist
a Append. Opens and writes to the end of the file or creates a new file if it doesn't exist
a+ Read/Append. Preserves file content by writing to the end of the file
x Write only. Creates a new file. Returns FALSE and an error if file already exists
x+ Read/Write. Creates a new file. Returns FALSE and an error if file already exists

Note: If the fopen() function is unable to open the specified file, it returns 0 (false).
Example

The following example generates a message if the fopen() function is unable to open the specified file:




$file=fopen("welcome.txt","r") or exit("Unable to open file!");
?>





Closing a File

The fclose() function is used to close an open file:

$file = fopen("test.txt","r");

//some code to be executed

fclose($file);
?>


Check End-of-file

The feof() function checks if the "end-of-file" (EOF) has been reached.

The feof() function is useful for looping through data of unknown length.

Note: You cannot read from files opened in w, a, and x mode!

if (feof($file)) echo "End of file";


Reading a File Line by Line

The fgets() function is used to read a single line from a file.

Note: After a call to this function the file pointer has moved to the next line.
Example

The example below reads a file line by line, until the end of file is reached:

$file = fopen("welcome.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "
";
}
fclose($file);
?>


Reading a File Character by Character

The fgetc() function is used to read a single character from a file.

Note: After a call to this function the file pointer moves to the next character.
Example

The example below reads a file character by character, until the end of file is reached:

$file=fopen("welcome.txt","r") or exit("Unable to open file!");
while (!feof($file))
{
echo fgetc($file);
}
fclose($file);
?>

SERVER side includes.....php

Server Side Includes

You can insert the content of a file into a PHP file before the server executes it, with the include() or require() function. The two functions are identical in every way, except how they handle errors. The include() function generates a warning (but the script will continue execution) while the require() function generates a fatal error (and the script execution will stop after the error).

These two functions are used to create functions, headers, footers, or elements that can be reused on multiple pages.

This can save the developer a considerable amount of time. This means that you can create a standard header or menu file that you want all your web pages to include. When the header needs to be updated, you can only update this one include file, or when you add a new page to your site, you can simply change the menu file (instead of updating the links on all web pages).
The include() Function

The include() function takes all the text in a specified file and copies it into the file that uses the include function.
Example 1

Assume that you have a standard header file, called "header.php". To include the header file in a page, use the include() function, like this:






Welcome to my home page



Some text






Example 2

Now, let's assume we have a standard menu file that should be used on all pages (include files usually have a ".php" extension). Look at the "menu.php" file below:




Home |
About Us |
Contact Us

The three files, "default.php", "about.php", and "contact.php" should all include the "menu.php" file. Here is the code in "default.php":



Welcome to my home page



Some text






If you look at the source code of the "default.php" in a browser, it will look something like this:



Home |
About Us |
Contact Us

Welcome to my home page


Some text





And, of course, we would have to do the same thing for "about.php" and "contact.php". By using include files, you simply have to update the text in the "menu.php" file if you decide to rename or change the order of the links or add another web page to the site.
The require() Function

The require() function is identical to include(), except that it handles errors differently.

The include() function generates a warning (but the script will continue execution) while the require() function generates a fatal error (and the script execution will stop after the error).

If you include a file with the include() function and an error occurs, you might get an error message like the one below.

PHP code:




include("wrongFile.php");
echo "Hello World!";
?>




Error message:

Warning: include(wrongFile.php) [function.include]:
failed to open stream:
No such file or directory in C:\home\website\test.php on line 5

Warning: include() [function.include]:
Failed opening 'wrongFile.php' for inclusion
(include_path='.;C:\php5\pear')
in C:\home\website\test.php on line 5

Hello World!

Notice that the echo statement is still executed! This is because a Warning does not stop the script execution.

Now, let's run the same example with the require() function.

PHP code:




require("wrongFile.php");
echo "Hello World!";
?>




Error message:

Warning: require(wrongFile.php) [function.require]:
failed to open stream:
No such file or directory in C:\home\website\test.php on line 5

Fatal error: require() [function.require]:
Failed opening required 'wrongFile.php'
(include_path='.;C:\php5\pear')
in C:\home\website\test.php on line 5

The echo statement was not executed because the script execution stopped after the fatal error.

It is recommended to use the require() function instead of include(), because scripts should not continue executing if files are missing or misnamed.

PHP date().....

The PHP Date() Function

The PHP date() function formats a timestamp to a more readable date and time.
Syntax

date(format,timestamp)


Parameter Description
format Required. Specifies the format of the timestamp
timestamp Optional. Specifies a timestamp. Default is the current date and time (as a timestamp)

PHP Date - What is a Timestamp?

A timestamp is the number of seconds since January 1, 1970 at 00:00:00 GMT. This is also known as the Unix Timestamp.
PHP Date - Format the Date

The first parameter in the date() function specifies how to format the date/time. It uses letters to represent date and time formats. Here are some of the letters that can be used:

* d - The day of the month (01-31)
* m - The current month, as a number (01-12)
* Y - The current year in four digits

An overview of all the letters that can be used in the format parameter, can be found in our PHP Date reference.

Other characters, like"/", ".", or "-" can also be inserted between the letters to add additional formatting:

echo date("Y/m/d");
echo "
";
echo date("Y.m.d");
echo "
";
echo date("Y-m-d");
?>

The output of the code above could be something like this:

2006/07/11
2006.07.11
2006-07-11


PHP Date - Adding a Timestamp

The second parameter in the date() function specifies a timestamp. This parameter is optional. If you do not supply a timestamp, the current time will be used.

In our next example we will use the mktime() function to create a timestamp for tomorrow.

The mktime() function returns the Unix timestamp for a specified date.
Syntax

mktime(hour,minute,second,month,day,year,is_dst)

To go one day in the future we simply add one to the day argument of mktime():

$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d", $tomorrow);
?>

The output of the code above could be something like this:

Tomorrow is 2006/07/12

PHP looping...

Looping

Very often when you write code, you want the same block of code to run a number of times. You can use looping statements in your code to perform this.

In PHP we have the following looping statements:

* while - loops through a block of code if and as long as a specified condition is true
* do...while - loops through a block of code once, and then repeats the loop as long as a special condition is true
* for - loops through a block of code a specified number of times
* foreach - loops through a block of code for each element in an array

The while Statement

The while statement will execute a block of code if and as long as a condition is true.
Syntax

while (condition)
code to be executed;

Example

The following example demonstrates a loop that will continue to run as long as the variable i is less than, or equal to 5. i will increase by 1 each time the loop runs:




$i=1;
while($i<=5)
{
echo "The number is " . $i . "
";
$i++;
}
?>





The do...while Statement

The do...while statement will execute a block of code at least once - it then will repeat the loop as long as a condition is true.
Syntax

do
{
code to be executed;
}
while (condition);

Example

The following example will increment the value of i at least once, and it will continue incrementing the variable i as long as it has a value of less than 5:




$i=0;
do
{
$i++;
echo "The number is " . $i . "
";
}
while ($i<5);
?>





The for Statement

The for statement is used when you know how many times you want to execute a statement or a list of statements.
Syntax

for (initialization; condition; increment)
{
code to be executed;
}

Note: The for statement has three parameters. The first parameter initializes variables, the second parameter holds the condition, and the third parameter contains the increments required to implement the loop. If more than one variable is included in the initialization or the increment parameter, they should be separated by commas. The condition must evaluate to true or false.
Example

The following example prints the text "Hello World!" five times:




for ($i=1; $i<=5; $i++)
{
echo "Hello World!
";
}
?>





The foreach Statement

The foreach statement is used to loop through arrays.

For every loop, the value of the current array element is assigned to $value (and the array pointer is moved by one) - so on the next loop, you'll be looking at the next element.
Syntax

foreach (array as value)
{
code to be executed;
}

Example

The following example demonstrates a loop that will print the values of the given array:




$arr=array("one", "two", "three");

foreach ($arr as $value)
{
echo "Value: " . $value . "
";
}
?>


PHP arrays.......

What is an array?

When working with PHP, sooner or later, you might want to create many similar variables.

Instead of having many similar variables, you can store the data as elements in an array.

Each element in the array has its own ID so that it can be easily accessed.

There are three different kind of arrays:

* Numeric array - An array with a numeric ID key
* Associative array - An array where each ID key is associated with a value
* Multidimensional array - An array containing one or more arrays

Numeric Arrays

A numeric array stores each element with a numeric ID key.

There are different ways to create a numeric array.
Example 1

In this example the ID key is automatically assigned:

$names = array("Peter","Quagmire","Joe");

Example 2

In this example we assign the ID key manually:

$names[0] = "Peter";
$names[1] = "Quagmire";
$names[2] = "Joe";

The ID keys can be used in a script:


$names[0] = "Peter";
$names[1] = "Quagmire";
$names[2] = "Joe";

echo $names[1] . " and " . $names[2] .
" are ". $names[0] . "'s neighbors";
?>

The code above will output:

Quagmire and Joe are Peter's neighbors


Associative Arrays

An associative array, each ID key is associated with a value.

When storing data about specific named values, a numerical array is not always the best way to do it.

With associative arrays we can use the values as keys and assign values to them.
Example 1

In this example we use an array to assign ages to the different persons:

$ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);

Example 2

This example is the same as example 1, but shows a different way of creating the array:

$ages['Peter'] = "32";
$ages['Quagmire'] = "30";
$ages['Joe'] = "34";

The ID keys can be used in a script:


$ages['Peter'] = "32";
$ages['Quagmire'] = "30";
$ages['Joe'] = "34";

echo "Peter is " . $ages['Peter'] . " years old.";
?>

The code above will output:

Peter is 32 years old.


Multidimensional Arrays

In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on.
Example

In this example we create a multidimensional array, with automatically assigned ID keys:

$families = array
(
"Griffin"=>array
(
"Peter",
"Lois",
"Megan"
),
"Quagmire"=>array
(
"Glenn"
),
"Brown"=>array
(
"Cleveland",
"Loretta",
"Junior"
)
);

The array above would look like this if written to the output:

Array
(
[Griffin] => Array
(
[0] => Peter
[1] => Lois
[2] => Megan
)
[Quagmire] => Array
(
[0] => Glenn
)
[Brown] => Array
(
[0] => Cleveland
[1] => Loretta
[2] => Junior
)
)

Example 2

Lets try displaying a single value from the array above:

echo "Is " . $families['Griffin'][2] .
" a part of the Griffin family?";

The code above will output:

Is Megan a part of the Griffin family?

Going on through php...

Conditional Statements

Very often when you write code, you want to perform different actions for different decisions.

You can use conditional statements in your code to do this.

* if...else statement - use this statement if you want to execute a set of code when a condition is true and another if the condition is not true
* elseif statement - is used with the if...else statement to execute a set of code if one of several condition are true

The If...Else Statement

If you want to execute some code if a condition is true and another code if a condition is false, use the if....else statement.
Syntax

if (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;

Example

The following example will output "Have a nice weekend!" if the current day is Friday, otherwise it will output "Have a nice day!":




$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
else
echo "Have a nice day!";
?>




If more than one line should be executed if a condition is true/false, the lines should be enclosed within curly braces:




$d=date("D");
if ($d=="Fri")
{
echo "Hello!
";
echo "Have a nice weekend!";
echo "See you on Monday!";
}
?>





The ElseIf Statement

If you want to execute some code if one of several conditions are true use the elseif statement
Syntax

if (condition)
code to be executed if condition is true;
elseif (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;

Example

The following example will output "Have a nice weekend!" if the current day is Friday, and "Have a nice Sunday!" if the current day is Sunday. Otherwise it will output "Have a nice day!":




$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>