Skip to main content

XSL, XML, DTD, XPath, XQuery, Schema, Web Services

XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents.

XSLT stands for XSL Transformations. XSLT to transform XML documents into other formats, like XHTML.

XSL is a family of recommendations for defining XML document transformation and presentation. It consists of three parts: XSL Transformations (XSLT) a language for transforming XML; The XML Path Language (XPath)

XSL is a language for expressing style sheets. An XSL style sheet is, like with CSS, a file that describes how to display an XML document of a given type. XSL shares the functionality and is compatible with CSS2 (although it uses a different syntax). It also adds:

A transformation language for XML documents: XSLT. Originally intended to perform complex styling operations, like the generation of tables of contents and indexes, it is now used as a general purpose XML processing language. XSLT is thus widely used for purposes other than XSL, like generating HTML web pages from XML data.
Advanced styling features, expressed by an XML document type which defines a set of elements called Formatting Objects, and attributes (in part borrowed from CSS2 properties and adding more complex ones.

XSL is based on and extends the Document Style Semantics and Specification Language (DSSSL) and the Cascading Style Sheet, level 1 (CSS1) standards. XSL is developed under the auspices of the World Wide Web Consortium (W3C). 


XSLT Example


XML Code: (file: catalog.xml)

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
    <cd>
        <title>XSL</title>
        <artist>Nilesh P</artist>
        <country>India</country>
        <company>Maharastra</company>
        <price>500</price>
        <year>2016</year>
    </cd>

</catalog>


XSLT Code: (file: catalog.xsl)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>My Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th style="text-align:left">Title</th>
        <th style="text-align:left">Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>


PHP File: (file: index.php)

<?php
// Load the XML source
$xml = new DOMDocument;
$xml->load('catalog.xml');

$xsl = new DOMDocument;
$xsl->load('catalog.xsl');

// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules

echo $proc->transformToXML($xml);



Your Result: 
(run the index.php file in browser, http://localhost/xsl/index.php)

My Collection

Title    Artist
XSL     Nilesh P


In the above file, the xsl:for-each element locates elements in the XML document and repeats a template for each one. The select attribute describes the element in the source document. The syntax for this attribute is called an XSL Pattern, and works like navigating a file system where a forward slash (/) selects subdirectories. The xsl:value-of element selects a child in the hierarchy and inserts the content of that child into the template.

Since an XSL style sheet is an XML file itself, the file begins with an xml declaration. The xsl:stylesheet element indicates that this document is a style sheet. The template has also been wrapped with xsl:template match="/" to indicate that this is a template that corresponds to the root (/) of the XML source document.
===================================================

XSL - The Style Sheet of XML?


HTML pages uses predefined tags, and the meaning of these tags is well understood: <p> means a paragraph and <h1> means a header, and the browser knows how to display these pages.

With XML we can use any tags we want, and the meaning of these tags are not automatically understood by the browser: <table> could mean a HTML table or maybe a piece of furniture. Because of the nature of XML, there is no standard way to display an XML document.

In order to display XML documents, it is necessary to have a mechanism to describe how the document should be displayed. One of these mechanisms is Cascading Style Sheets (CSS), but XSL (eXtensible Stylesheet Language) is the preferred style sheet language of XML, and XSL is far more sophisticated than the CSS  used by HTML.


XSL - More than a Style Sheet


XSL consists of two parts:

a method for transforming XML documents
a method for formatting XML documents
If you don't understand the meaning of this, think of XSL as a language that can transform XML into HTML, a language that can filter and sort XML data and a language that can format XML data, based on the data value, like displaying negative numbers in red.


XSL - What can it do?


XSL can be used to define how an XML file should be displayed by transforming the XML file into a format that is recognizable to a browser. One such format is HTML. Normally XSL does this by transforming each XML element into an HTML element.

XSL can also add completely new elements into the output file, or remove elements. It can rearrange and sort the elements, test and make decisions about which elements to display, and a lot more.


A note about XSL in IE5


XSL in Internet Explorer 5.0 is not 100% compatible with the latest released W3C XSL standard. That is because IE 5 was released before the standard was completely settled. Microsoft has promised to solve this problem in the 5.5 release.

===================================================

Questions and Answers on XSL


How is XSL different from CSS?
XSL uses a XML notation, CSS uses its own. In CSS, the formatting object tree is almost the same as the source tree, and inheritance of formatting properties is on the source tree. In XSL, the formatting object tree can be radically different from the source tree, and inheritance of formatting properties is on the formatting object tree.
Most modern Web browsers support both CSS and XSLT; there are also many stand-alone XSLT implementations.

Will XSL replace CSS?
No. They are likely to co-exist since they meet different needs. XSL is intended for complex formatting where the content of the document might be displayed in multiple places; for example the text of a heading might also appear in a dynamically generated table of contents. CSS is intended for dynamic formatting of online documents for multiple media; its strictly declarative nature limits its capabilities but also makes it efficient and easy to generate and modify in the content-generation workflow. So they are two different tools; for some tasks, CSS is the appropriate choice and for some tasks, XSL. They can also be used together - use XSL on the server to condense or customize some XML data into a simpler XML document, then use CSS to style it on the client.

How is XSL different from DSSSL? From DSSSL-O?
DSSSL is an International Standard style sheet language. It is particularly used for formatting of print documents. DSSSL-O is a profile of DSSSL which removes some functionality and adds capabilities to make it more suited for online documentation. XSL draws on DSSSL and the DSSSL-O work and continues the trend towards a Web-oriented style sheet language by integrating experience with CSS.

Will XSL replace DSSSL?
DSSSL has capabilities that XSL does not, and continues in use in the print publishing industry. Experience with XSL might be used in a future revision of DSSSL, but it is too early to say.
So, CSS is for HTML and XSL is for XML?
No, CSS can be used with HTML and also with XML, provided that the XML document has a reasonably linear structure that can be displayed without extensive manipulation. See the CSS2 Recommendation for details.
XSL is targeted at XML, in particular highly-structured, data-rich documents that require extensive formatting.

Should I render all my XML documents to HTML on the server?
Unless you are very careful to retain semantics, no. XSL can be used server-side and client-side. The XSL Submission has two classes of output: DSSSL-style flow objects and HTML tags. Unfortunately, the combination of server-side processing and HTML tag output can result in completely inaccessible, hard to search, hard to index presentational HTML (the sort that is a mass of FONT and BR tags, spacer gifs - you know, the sort of single-shot presentational mess that style sheets were designed to avoid).
The trouble is that by "rendering" to HTML, all that remains of your carefully crafted XML semantics are the presentational aspects - block element, this font, that weight - which makes it hard to generate decent HTML.

===================================================
XHTML - Extensible Hypertext Markup Language (XHTML) is part of the family of XML markup languages. It mirrors or extends versions of the widely used Hypertext Markup Language (HTML), the language in which Web pages are formulated.

What Is XHTML?
  • XHTML stands for EXtensible HyperText Markup Language
  • XHTML is almost identical to HTML
  • XHTML is stricter than HTML
  • XHTML is HTML defined as an XML application
  • XHTML is supported by all major browsers 
The Most Important Differences from HTML:
Document Structure
  • XHTML DOCTYPE is mandatory
  • The xmlns attribute in <html> is mandatory
  • <html>, <head>, <title>, and <body> are mandatory
  • XHTML Elements
  • XHTML elements must be properly nested (<b><i>This text is bold and italic</i></b>)
  • XHTML elements must always be closed (<p>This is a paragraph</p>)
  • XHTML elements must be in lowercase (<body><p></p></body>)
  • Empty Elements Must Also Be Closed  (A break: <br>)
  • XHTML documents must have one root element

XHTML Attributes
  • Attribute names must be in lower case
  • Attribute values must be quoted
  • Attribute minimization is forbidden
The <html>, <head>, <title>, and <body> elements must also be present, and the xmlns attribute in <html> must specify the xml namespace for the document.

How to Convert from HTML to XHTML
  • Add an XHTML <!DOCTYPE> to the first line of every page
  • Add an xmlns attribute to the html element of every page
  • Change all element names to lowercase
  • Close all empty elements
  • Change all attribute names to lowercase
  • Quote all attribute values

===================================================

XML

XML is a software- and hardware-independent tool for storing and transporting data.
XML stands for EXtensible Markup Language.
XML was designed to store and transport data.
XML was designed to be both human- and machine-readable.
XML is a markup language much like HTML
XML was designed to be self-descriptive
XML is a W3C Recommendation

Example:

 <?xml version="1.0" encoding="UTF-8"?>
<note>
  <to>Nilesh</to>
  <from>Kamlesh</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

The Difference Between XML and HTML

XML and HTML were designed with different goals:

XML was designed to carry data - with focus on what data is
HTML was designed to display data - with focus on how data looks
XML tags are not predefined like HTML tags are

XML Simplifies Things

It simplifies data sharing
It simplifies data transport
It simplifies platform changes
It simplifies data availability

===================================================

What is XPath?


XPath is a syntax for defining parts of an XML document
XPath uses path expressions to navigate in XML documents
XPath contains a library of standard functions
XPath is a major element in XSLT
XPath is also used in XQuery, XPointer and XLink
XPath is a W3C recommendation

XPath Path Expressions
XPath uses path expressions to select nodes or node-sets in an XML document. These path expressions look very much like the expressions you see when you work with a traditional computer file system.

Today XPath expressions can also be used in JavaScript, Java, XML Schema, PHP, Python, C and C++, and lots of other languages.

XPath is Used in XSLT
XPath is a major element in the XSLT standard. Without XPath knowledge you will not be able to create XSLT documents.

XPath Example

We will use the following XML document:

<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book category="cooking">
  <title lang="en">Everyday Italian</title>
  <author>Giada De Laurentiis</author>
  <year>2005</year>
  <price>30.00</price>
</book>

<book category="children">
  <title lang="en">Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>

<book category="web">
  <title lang="en">XQuery Kick Start</title>
  <author>James McGovern</author>
  <author>Per Bothner</author>
  <author>Kurt Cagle</author>
  <author>James Linn</author>
  <author>Vaidyanathan Nagarajan</author>
  <year>2003</year>
  <price>49.99</price>
</book>

<book category="web">
  <title lang="en">Learning XML</title>
  <author>Erik T. Ray</author>
  <year>2003</year>
  <price>39.95</price>
</book>

</bookstore>
In the table below we have listed some XPath expressions and the result of the expressions:

XPath Expression    Result
/bookstore/book[1]    Selects the first book element that is the child of the bookstore element
/bookstore/book[last()]    Selects the last book element that is the child of the bookstore element
/bookstore/book[last()-1]    Selects the last but one book element that is the child of the bookstore element
/bookstore/book[position()<3]    Selects the first two book elements that are children of the bookstore element
//title[@lang]    Selects all the title elements that have an attribute named lang
//title[@lang='en']    Selects all the title elements that have a "lang" attribute with a value of "en"
/bookstore/book[price>35.00]    Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00
/bookstore/book[price>35.00]/title    Selects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00

===================================================

What is XQuery?


XQuery is the language for querying XML data
XQuery for XML is like SQL for databases
XQuery is built on XPath expressions
XQuery is supported by all major databases
XQuery is a W3C Recommendation


XQuery is About Querying XML

XQuery is a language for finding and extracting elements and attributes from XML documents.
Here is an example of what XQuery could solve:
"Select all CD records with a price less than $10 from the CD collection stored in cd_catalog.xml"


XQuery - Examples of Use
XQuery can be used to:

Extract information to use in a Web Service
Generate summary reports
Transform XML data to XHTML
Search Web documents for relevant information

Example:

for $x in doc("books.xml")/bookstore/book
where $x/price>30
return $x/title

The result will be:

<title lang="en">XQuery Kick Start</title>
<title lang="en">Learning XML</title>

Example:

XQuery Conditional Expressions
"If-Then-Else" expressions are allowed in XQuery.

Look at the following example:

for $x in doc("books.xml")/bookstore/book
return    if ($x/@category="CHILDREN")
then <child>{data($x/title)}</child>
else <adult>{data($x/title)}</adult>

===================================================

DTD

DTD - A document type definition (DTD) is a set of markup declarations that define a document type for an SGML-family markup language (SGML, XML, HTML).

A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes. A DTD can be declared inline inside an XML document, or as an external reference.

A DTD states what tags and attributes are used to describe content in an SGML, XML or HTML document, where each tag is allowed, and which tags can appear within other tags.

For example, in a DTD one could say that LIST tags can contain ITEM tags, but ITEM tags cannot contain LIST tags. In some editors, when authors are inputting information, they can place tags only where the DTD allows. This ensures that all the documentation is formatted the same way. Applications will use a document's DTD to properly read and display a document's contents. Changes in the format of the document can be easily made by modifying the DTD.

A Document Type Definition (DTD) is a specific document defining and constraining definition or set of statements that follow the rules of the Standard Generalized Markup Language (SGML) or of the Extensible Markup Language (XML), a subset of SGML. A DTD is a specification that accompanies a document and identifies what the funny little codes (or markup) are that, in the case of a text document, separate paragraphs, identify topic headings, and so forth and how each is to be processed. By mailing a DTD with a document, any location that has a DTD "reader" (or "SGML compiler") will be able to process the document and display or print it as intended. This means that a single standard SGML compiler can serve many different kinds of documents that use a range of different markup codes and related meanings. The compiler looks at the DTD and then prints or displays the document accordingly.

A DTD is associated with an XML or SGML document by means of a document type declaration (DOCTYPE). The DOCTYPE appears in the syntactic fragment doctypedecl near the start of an XML document. The declaration establishes that the document is an instance of the type defined by the referenced DTD.

DTDs make two sorts of declaration:
  • an optional external subset
  • an optional internal subset
The purpose of a DTD is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements. A DTD can be declared inline in your XML document, or as an external reference.

Internal DTD

This is an XML document with a Document Type Definition.

<?xml version="1.0"?>
<!DOCTYPE note [
  <!ELEMENT note    (to,from,heading,body)>
  <!ELEMENT to      (#PCDATA)>
  <!ELEMENT from    (#PCDATA)>
  <!ELEMENT heading (#PCDATA)>
  <!ELEMENT body    (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note> 
The DTD is interpreted like this:
!ELEMENT note (in line 2) defines the element "note" as having four elements: "to,from,heading,body".
!ELEMENT to (in line 3) defines the "to" element  to be of the type "CDATA".
!ELEMENT from (in line 4) defines the "from" element to be of the type "CDATA"
and so on.....



External DTD

This is the same XML document with an external DTD.

<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note> 
This is a copy of the file "note.dtd" containing the Document Type Definition:

<?xml version="1.0"?>
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>

XML provides an application independent way of sharing data. With a DTD, independent groups of people can agree to use a common DTD for interchanging data. Your application can use a standard DTD to verify that data that you receive from the outside world is valid. You can also use a DTD to verify your own data.


    The declarations in the internal subset form part of the DOCTYPE in the document itself. The declarations in the external subset are located in a separate text file. The external subset may be referenced via a public identifier and/or a system identifier. Programs for reading documents may not be required to read the external subset.

    Note that any valid SGML or XML document that references an external subset in its DTD, or whose body contains references to parsed external entities declared in its DTD (including those declared within its internal subset), may only be partially parsed but cannot be fully validated by validating SGML or XML parsers in their standalone mode (this means that these validating parsers don't attempt to retrieve these external entities, and their replacement text is not accessible).

    However, such documents are still fully parsable in the non-standalone mode of validating parsers, which signals an error if it can't locate these external entities with their specified public identifier (FPI) or system identifier (a URI), or are inaccessible. (Notations declared in the DTD are also referencing external entities, but these unparsed entities are not needed for the validation of documents in the standalone mode of these parsers: the validation of all external entities referenced by notations is left to the application using the SGML or XML parser). Non-validating parsers may eventually attempt to locate these external entities in the non-standalone mode (by partially interpreting the DTD only to resolve their declared parsable entities), but do not validate the content model of these documents.

    Example:

    The following example of a DOCTYPE contains both public and system identifiers:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


    Example:

    //valid xml is

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE note SYSTEM "Note.dtd">
    <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    </note>

    //dtd for above xml is

    <!DOCTYPE note
    [
    <!ELEMENT note (to,from,heading,body)>
    <!ELEMENT to (#PCDATA)>
    <!ELEMENT from (#PCDATA)>
    <!ELEMENT heading (#PCDATA)>
    <!ELEMENT body (#PCDATA)>
    ]>

    The DTD above is interpreted like this:

    !DOCTYPE note defines that the root element of the document is note
    !ELEMENT note defines that the note element must contain the elements: "to, from, heading, body"
    !ELEMENT to defines the to element to be of type "#PCDATA"
    !ELEMENT from defines the from element to be of type "#PCDATA"
    !ELEMENT heading defines the heading element to be of type "#PCDATA"
    !ELEMENT body defines the body element to be of type "#PCDATA"

    Example:


    Using DTD for Entity Declaration
    A doctype declaration can also be used to define special characters and character strings, used in the document:

    Example
    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE note [
    <!ENTITY nbsp "&#xA0;"> 
    <!ENTITY writer "Writer: Donald Duck.">
    <!ENTITY copyright "Copyright: W3Schools.">
    ]>

    <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    <footer>&writer;&nbsp;&copyright;</footer>
    </note>


    When to Use a DTD/Schema?

    With a DTD, independent groups of people can agree to use a standard DTD for interchanging data.
    With a DTD, you can verify that the data you receive from the outside world is valid.
    You can also use a DTD to verify your own data.
    ===================================================

    Schema

    An XML Schema describes the structure of an XML document, just like a DTD.

    An XML document with correct syntax is called "Well Formed".

    An XML document validated against an XML Schema is both "Well Formed" and "Valid".

    XSD - The XML Schema language is also referred to as XML Schema Definition (XSD). 

    XML Schema
    XML Schema is an XML-based alternative to DTD:

    <xs:element name="note">

    <xs:complexType>
      <xs:sequence>
        <xs:element name="to" type="xs:string"/>
        <xs:element name="from" type="xs:string"/>
        <xs:element name="heading" type="xs:string"/>
        <xs:element name="body" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>

    </xs:element>

    The Schema above is interpreted like this:

    <xs:element name="note"> defines the element called "note"
    <xs:complexType> the "note" element is a complex type
    <xs:sequence> the complex type is a sequence of elements
    <xs:element name="to" type="xs:string"> the element "to" is of type string (text)
    <xs:element name="from" type="xs:string"> the element "from" is of type string
    <xs:element name="heading" type="xs:string"> the element "heading" is of type string
    <xs:element name="body" type="xs:string"> the element "body" is of type string

    XML Schemas are More Powerful than DTD
    XML Schemas are written in XML
    XML Schemas are extensible to additions
    XML Schemas support data types
    XML Schemas support namespaces
    Why Use an XML Schema?
    With XML Schema, your XML files can carry a description of its own format.

    With XML Schema, independent groups of people can agree on a standard for interchanging data.

    With XML Schema, you can verify data.

    XML Schemas Support Data Types

    One of the greatest strength of XML Schemas is the support for data types:

    It is easier to describe document content
    It is easier to define restrictions on data
    It is easier to validate the correctness of data
    It is easier to convert data between different data types

    XML Schemas use XML Syntax
    Another great strength about XML Schemas is that they are written in XML:

    You don't have to learn a new language
    You can use your XML editor to edit your Schema files
    You can use your XML parser to parse your Schema files
    You can manipulate your Schemas with the XML DOM
    You can transform your Schemas with XSLT

    ===================================================

    Web Services


    • Web services are application components
    • Web services communicate using open protocols
    • Web services are self-contained and self-describing
    • Web services can be discovered using UDDI
    • Web services can be used by other applications
    • HTTP and XML is the basis for Web services


    XML Web Services
    • Web services are web application components.
    • Web services can be published, found, and used on the Web.
    • This tutorial introduces WSDL, SOAP, RDF, and RSS.

    WSDL
    • WSDL stands for Web Services Description Language
    • WSDL is an XML-based language for describing Web services.
    • WSDL is a W3C recommendation


    SOAP
    • SOAP stands for Simple Object Access Protocol
    • SOAP is an XML based protocol for accessing Web Services.
    • SOAP is based on XML
    • SOAP is a W3C recommendation


    RDF
    • RDF stands for Resource Description Framework
    • RDF is a framework for describing resources on the web
    • RDF is written in XML
    • RDF is a W3C Recommendation


    RSS
    • RSS stands for Really Simple Syndication
    • RSS allows you to syndicate your site content
    • RSS defines an easy way to share and view headlines and content
    • RSS files can be automatically updated
    • RSS allows personalized views for different sites
    • RSS is written in XML

    =================================================== 

    Comments

    Popular posts from this blog

    Learn phpfox

    PHPFox  is a social network script, it is an internet application and when you install it, it is a website. The  phpfox  script comes in 3 packages, each with a different set of modules. it has two products: 1. Nebula (upto phpfox 3.8) 2. Neutron (Newer) You can check the demo on :  http://www.phpfox.com =================================================== To clear cache in phpfox follow the following steps, admincp >> Tools >> Maintenance >> Cache Manager >> Click on Clear All button =================================================== To work facebook app on local Following settings need to done in facebook app   1) go => setting => Advance 2) see "OAuth Settings" area and set "Valid OAuth redirect URIs" =  http:// projectdomain /index.php?do=/user/login/, http:// projectdomain .com/index.php?do=/user/register/, http:// projectdomain .com, http:// projectdomain .com/index.php 3) en...

    Interview PHP

    >> Why do you want to work at our company? Sir, It is a great privilege for anyone to work in a reputed company like yours. When I read about your company I found that my skills are matching your requirements.  Where I can showcase my technical skills to contribute to the company growth. >> What are your strengths? I am very much hard working and optimistic. Hard Working: Work with dedication and determination. Optimistic: work with positive attitude. I am a team player. I am also very hardworking, and will do what it takes to get the job done. >> What are your weaknesses? Gets nervous when talk to strangers I am a bit lazy about which I am not interested I tend to trust people too easily. I am working on it. >> Why should I hire you? With reference to my work experience, I satisfy all the requirement for this job. I am sincere with my work and would never let you down in anyway. I promise you will never regret for the decision to a...

    How to Make Your Own PHP Captcha Generator

    In this article we will create file based simple yet successful captcha generator. 3 Major Anti-spamming techniques used? Mathematical Operation like Random number + Random Number = -> The user must specify the answer Random word -> User must type the word Random question -> Obvious one which the user should answer correctly [ex: Are you human?] How Captcha works? The captcha generator generates an IMAGE with the question and then put up a session variable storing the value. User input though an input box. Using php POST, we compare the session variable data with the user input and tell whether its a bot or human. Its coding time The Code First let's write the php script which generates the captcha image. We use the simple header-content change technique, from which we can easily bring up an image from a given text. captcha.php PHP Code: array("Num" => "Num"), 1 => array("Are y...