Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
 Discussion Forums
 HTML, XML, JavaScript...
 Software Reviews
 Editors,Others...
 Top100
 JavaScript Tutorials, ...
 Tutorials
 ASP, CSS, Databases...
 Discussion List
 FAQ, Roundup, Configure ...
 Authoring
 HTML, JavaScript, CSS...
 Design
 Layout, Navigation,...
 Graphics
 Tools, Colors, Images...
 Software
 Browsers, Editors, XML...
 Internet
 Domains, E-Commerce, ...
 WDVL Resources
  Intermdiate, Tutorials,...
 WDVL
 Discussion Lists, Top 100,...
 Technology Jobs


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Top 10 Articles
  1. Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
  2. JavaScript Tutorial for Programmers
  3. Design
  4. JavaScript Tutorial for Programmers - Objects
  5. JavaScript Tutorial for Programmers - JavaScript Grammar
  6. JavaScript Tutorial for Programmers - Versions of JavaScript
  7. Cascading Style Sheets
  8. JavaScript Tutorial for Programmers - Embedding JavaScript
  9. JavaScript Tutorial for Programmers - Functions
  10. Authoring JavaScript
Domain Name Lookup
Search to find the availability of a domain name. Just enter the complete domain name with extension (.com, .net, .edu)

Non-Parsed Header Scripts

Non-Parsed Header Scripts

  • In this section, we will outline several ways to use CGI scripts to push data to a client such as when you want to animate text. Specifically, we will discuss nph (non-parsed header) scripts.

  • Surely, newer technologies, such as Java, or plug-ins, such as Shockwave, are better suited for complex animation.

  • However, the ability to use NPH scripts in creative ways is an important part of any CGI programmer's box of tools. NPH scripts add another dimension to multimedia and can make your site more diverse. They can also be used when the big guns of Java or Shockwave are not appropriate.

  • Nonparsed header scripts are used when we want to bypass the server.

  • Usually, when we use the line

    print "Content-type: text/plain\n\n";
    

    we count on the fact that the server that executes the script will fill in the rest of the HTTP protocol lines, such as the "200 OK" status codes, the date and time, and other information defined in the protocol.

  • With NPH scripts, we must generate those HTTP protocol messages internally, bypassing server parsing. In other words, we output directly to the browser without Web server intervention.

  • Most of the information that you might pass to the browser is optional. However, you should at least return the MIME content type of the data, the HTTP protocol revision, the status of the program, and the server name and version.

  • By bypassing the server, you can communicate directly with the browser. As long as the browser listens, you can continue to feed it more information. In this way, you can use cell animation to create an animated series of text or images.

  • However, the use of NPH scripts requires that all scripts begin with the characters nph-. This is the convention used by servers to recognize an NPH script. If you rename the script, the server will not know to treat it as an NPH script and instead will run it as a normal script.

Because you are bypassing the server, you need to be careful that your NPH scripts do not run forever, because they will run to completion whether or not the browser has already moved to another page. If the script loops infinitely, it may never know to stop and may eat up your server resources.

  • Let's take a look at a simple nph script which animates a countdown:
    !/usr/local/bin/perl
    print "$ENV{'SERVER_PROTOCOL'} 200 OK\n";
    print "Server: $ENV{'SERVER_SOFTWARE'}\n";
    print "Content-type: text/plain\n\n";
    $| = 1;
    for ($loop = 10; $loop >= 0; $loop--)
      {
      print "$loop\n";
      sleep (1);
      }
    print "Blast Off!\n";
    exit (0);
    

  • On the other hand, you may want to include HTML or images in your animation. In this case, you must specify a content type and a boundary:
    #!/usr/local/bin/perl
    $| = 1;
    print "$ENV{'SERVER_PROTOCOL'} 200 OK\n";
    print "Server: $ENV{'SERVER_SOFTWARE'}\n";
    print "Content-type: 
    multipart/x-mixed-replace;
    boundary=ARandomString\n\n";
    
    		# Begin sending words
    
    print "--ARandomString\n";
     
        # Create a list of words that you 
        # want to be animated.
     
    @words = ("This", "is", "a", "test");
     
        # Set $loop equal to zero (since all 
        # arrays start with 0 as their first
        # value).  Then begin incrementing 
        # $loop by one ($loop++) until $loop is
        # equivalent to the number of words in 
        # @words ($loop <= @words;)
    
    for ($loop = 0; $loop <= @words; $loop++)
        {
    
        # For every value of $loop, print out 
        # the value in @words that corresponds
        # to the value of loop.  So when $loop 
        # equals zero, print out the first
        # word in the @words array and when 
        # $loop equals 1, print out the second
        # word...and so on.  Then pause a second 
        # and print out the flag which will notify 
        # the browser to replace the next word 
        # with the current one.
      print "Content-type: text/plain\n\n";
      print "$words[$loop]\n";
      sleep (1);
      print "\n--ARandomString\n";
      }
    
    		# Quit-a-mundo
    
        exit (0);
    

Additional Resources:

Exercise Four
Table of Contents
Handling Image Input


Up to => Home / Authoring / Scripting / Tutorial




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers