home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
- <html xmlns="http://www.w3.org/TR/xhtml1">
- <head>
- <title>perlwin32faq7 - Web Programming</title>
- <link rev="made" href="mailto:bjepson@debian.ids.net" />
- <meta name="GENERATOR" charset="iso-8859-1" />
- <link rel="STYLESHEET" href="../win32prk.css" type="text/css"
- media="screen" />
- </head>
-
- <body bgcolor="#ffffff">
- <!-- beginning of leaf header-->
-
- <table width="100%">
- <tr>
- <td bgcolor="000000" width="70" height="31"><a href=
- "http://www.activestate.com/"><img src="ASbutton.gif" alt=
- "ActiveState Home Page" border="0" width="68" height=
- "30" /></a></td>
-
- <td width="10" bgcolor="#ffffff"> </td>
-
- <td valign="middle" bgcolor="#cc0066"><font face=
- "sans-serif" size="+1" color="#ff99cc">
- Win32 FAQ</font></td>
- </tr>
- </table>
- <!-- end of leaf content--><!-- INDEX BEGIN -->
-
- <ul>
- <li><a href="#NAME">NAME</a></li>
-
- <li>
- <a href="#DESCRIPTION">DESCRIPTION</a>
-
- <ul>
- <li><a href="#What_is_HTTP_and_how_do_I_get_m">What is
- HTTP, and how do I get more information on it?</a></li>
-
- <li><a href="#What_is_CGI_and_how_do_I_get_mo">What is
- CGI, and how do I get more information on it?</a></li>
-
- <li><a href="#How_do_I_return_a_graphics_file_">How do I
- return a graphics file from a CGI script?</a></li>
-
- <li><a href="#My_CGI_scripts_don_t_seem_to_run">My CGI
- scripts don't seem to run right under PerlIS.</a></li>
-
- <li><a href="#How_does_my_script_know_if_it_s_">How does
- my script know if it's running under Perl for Win32
- or</a></li>
-
- <li><a href="#How_does_my_script_know_if_it_s_">How does
- my script know if it's running under Perl for Win32
- or</a></li>
-
- <li><a href="#What_CGI_modules_run_with_Perl_f">What CGI
- modules run with Perl for Win32?</a></li>
-
- <li><a href="#How_do_I_use_redirection_in_my_s">How do I
- use redirection in my script?</a></li>
-
- <li><a href="#What_are_cookies_and_how_do_I_us">What are
- cookies and how do I use them?</a></li>
-
- <li><a href="#How_do_I_get_the_e_mail_address_">How do I
- get the e-mail address of the user?</a></li>
-
- <li><a href="#I_need_a_CGI_script_to_do_a_cert">I need a
- CGI script to do a certain task. Has anyone done it
- before?</a></li>
-
- <li><a href="#How_do_I_test_my_CGI_programs_th">How do I
- test my CGI programs that take arguments without
- running</a></li>
-
- <li><a href="#The_Content_Type_header_field_I">The
- Content-Type: header field I output from my CGI script
- shows up</a></li>
-
- <li><a href="#When_I_try_to_run_a_CGI_script_f">When I
- try to run a CGI script from my browser, it tries
- to</a></li>
-
- <li><a href="#What_s_Perl_for_WSAPI_">What's Perl for
- WSAPI?</a></li>
- </ul>
- </li>
-
- <li><a href="#AUTHOR_AND_COPYRIGHT">AUTHOR AND
- COPYRIGHT</a></li>
- </ul>
- <!-- INDEX END -->
- <hr />
- <br />
-
- <h1><a name="NAME">NAME</a></h1>
-
- <p>perlwin32faq7 - Web Programming <font size="-1">(CGI</font>
- and PerlIS)</p>
- <br />
- <hr />
-
- <h1><a name="DESCRIPTION">DESCRIPTION</a></h1>
-
- <p>Web development with Perl for Win32</p>
- <br />
- <hr />
-
- <h2><a name="What_is_HTTP_and_how_do_I_get_m">What is HTTP, and
- how do I get more information on it?</a></h2>
-
- <p> <font size="-1">HTTP</font> (HyperText Transfer Protocol)
- is the protocol that web browsers use to talk to web servers.
- The official specification for the <font size="-1">HTTP</font>
- standard is available on the <font size="-1">W3</font>
- Consortium web server at:</p>
- <br />
- <pre>
- <a href=
- "http://www.w3.org/pub/WWW/Protocols/">http://www.w3.org/pub/WWW/Protocols/</a>
- </pre>
-
- <p>Some more readable introductions can be found on the Yahoo
- <font size="-1">HTTP</font> page at:</p>
- <br />
- <pre>
- <a href=
- "http://www.yahoo.com/Computers_and_Internet/Internet/World_Wide_Web/HTTP/">http://www.yahoo.com/Computers_and_Internet/Internet/World_Wide_Web/HTTP/</a>
- </pre>
- <br />
- <hr />
-
- <h2><a name="What_is_CGI_and_how_do_I_get_mo">What is CGI, and
- how do I get more information on it?</a></h2>
-
- <p> <font size="-1">CGI</font> (Common Gateway Interface) is a
- protocol used by web servers to run server programs. Scripts
- that support the <font size="-1">CGI</font> protocol are
- sometimes called <font size="-1">``CGI</font> scripts''; this
- leads to the unfortunate misperception that <font size="-1">
- CGI</font> is a language of its own.</p>
-
- <p>The classic information on <font size="-1">CGI</font> is
- available on the <font size="-1">NCSA</font> server at:</p>
- <br />
- <pre>
- <a href=
- "http://hoohoo.ncsa.uiuc.edu/cgi/">http://hoohoo.ncsa.uiuc.edu/cgi/</a>
- </pre>
-
- <p>If you haven't read this, read it now. If it doesn't click
- for you, you can check the Yahoo <font size="-1">CGI</font>
- page at:</p>
- <br />
- <pre>
- <a href=
- "http://www.yahoo.com/Computers_and_Internet/Internet/World_Wide_Web/CGI___Common_Gateway_Interface/">http://www.yahoo.com/Computers_and_Internet/Internet/World_Wide_Web/CGI___Common_Gateway_Interface/</a>
- </pre>
-
- <p>(All one <font size="-1">URL)</font></p>
-
- <p>Try also the following <font size="-1">URL</font> for <font
- size="-1">CGI</font> programming in Perl:</p>
- <br />
- <pre>
- <a href=
- "http://www.perl.com/CPAN-local/doc/FAQs/cgi/perl-cgi-faq.html">http://www.perl.com/CPAN-local/doc/FAQs/cgi/perl-cgi-faq.html</a>
- </pre>
-
- <p>If you still don't get it, try one of the
- ``get-rich-quick-by-writing-CGI-scripts'' books at your local
- bookstores.</p>
- <br />
- <hr />
-
- <h2><a name="How_do_I_return_a_graphics_file_">How do I return
- a graphics file from a CGI script?</a></h2>
-
- <p>One of the big differences between <font size="-1">
- UNIX</font> and Win32 platforms is that on Win32 there's a
- difference between text or <font size="-1">ASCII</font> files
- and binary file. To return a graphics file, you need to specify
- that the file is a binary file, and that the standard output
- stream should accept binary data. Try something like this:</p>
- <br />
- <pre>
- $MY_FILE_NAME = 'Penelope.jpg';
- $CHUNK_SIZE = 4096;
-
- open( MY_FILE, "<$MY_FILE_NAME" )
- or die( "Can't open $MY_FILE_NAME: $!\n" );
-
- print "Content-type: image/jpeg\r\n";
- print "\r\n";
-
- binmode( MY_FILE ); # These are crucial!
- binmode( STDOUT );
-
- while ( $cb = read( MY_FILE, $data, $CHUNK_SIZE ) ) {
- print $data;
- }
-
- close( MY_FILE );
- </pre>
- <br />
- <hr />
-
- <h2><a name="My_CGI_scripts_don_t_seem_to_run">My CGI scripts
- don't seem to run right under PerlIS.</a></h2>
-
- <p>Earlier versions of Perl for <font size="-1">ISAPI</font>
- did not output headers correctly, and this caused Perl for
- <font size="-1">ISAPI</font> scripts to misbehave. You could
- work around this in earlier versions of PerlIS by sending the
- headers at the beginning of your script like this:</p>
- <br />
- <pre>
- print <<"END";
- HTTP/1.0 200 OK
- Content-Type: text/html
-
- END
- </pre>
-
- <p>This is no longer necessary with the current version of Perl
- for <font size="-1">ISAPI,</font> as Perl for <font size="-1">
- ISAPI</font> sends the correct headers. The Registry value that
- governs this is <code>EnableCGIHeader</code>, a <font size=
- "-1">REG_DWORD</font> value that is set to 1 by default. This
- value is stored under the Registry key
- HKEY_LOCAL_MACHINE\SOFTWARE\ActiveState\PerlIS. If you need to
- turn off the automatic generation of the header, set this value
- to 0.</p>
- <br />
- <hr />
-
- <h2><a name="How_does_my_script_know_if_it_s_">How does my
- script know if it's running under Perl for Win32 or Perl for
- ISAPI?</a></h2>
-
- <p>Perl for <font size="-1">ISAPI</font> sets an environment
- variable, <code>PERLXS</code>, for scripts that are executed
- under Perl for <font size="-1">ISAPI.</font></p>
- <br />
- <pre>
- my $running_under_perlis = $ENV{PERLXS} eq 'PerlIS';
- </pre>
- <br />
- <hr />
-
- <h2><a name="How_does_my_script_know_if_it_s_">How does my
- script know if it's running under Perl for Win32 or Perl for
- WebSite?</a></h2>
-
- <p>Perl for WebSite sets an environment variable, <code>
- PERLXS</code>, for scripts that are executed under Perl for
- WebSite.</p>
- <br />
- <pre>
- my $running_under_perlws = $ENV{PERLXS} eq 'PerlWS';
- </pre>
- <br />
- <hr />
-
- <h2><a name="What_CGI_modules_run_with_Perl_f">What CGI modules
- run with Perl for Win32?</a></h2>
-
- <p>The <em>CGI.pm</em> module works with Perl for Win32. It's
- included with Perl for Win32, and you can use it in your
- program with the statement <code>use CGI</code>. Complete
- documentation for the <font size="-1">CGI</font> module is
- embedded in the module, and can be read with <code>perldoc
- CGI</code>. Further documentation is available at:</p>
- <br />
- <pre>
- <a href=
- "http://www-genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html">http://www-genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html</a>
- </pre>
- <br />
- <hr />
-
- <h2><a name="How_do_I_use_redirection_in_my_s">How do I use
- redirection in my script?</a></h2>
-
- <p>You can use redirection to point the client browser to
- another file or script, usually in a way that's invisible to
- the user. The <font size="-1">CGI</font> module provides the
- <code>redirect()</code> function for this purpose. The
- following code redirects the client browser to <a href=
- "http://www.perl.com,">http://www.perl.com,</a> and works with
- both <font size="-1">CGI</font> or PerlIS:</p>
- <br />
- <pre>
- use CGI qw(:standard);
- print redirect('<a href=
- "http://www.perl.com">http://www.perl.com</a>');
- </pre>
- <br />
- <hr />
-
- <h2><a name="What_are_cookies_and_how_do_I_us">What are cookies
- and how do I use them?</a></h2>
-
- <p>Cookies are packets of data that a server can give to a
- client, such as a browser, to maintain information even after
- the browser has left this site. This can be used to to identify
- the client in future interactions or to store user preferences.
- Cookies were first defined by Netscape, and the definition of
- cookies can be found at:</p>
- <br />
- <pre>
- <a href=
- "http://home.netscape.com/newsref/std/cookie_spec.html">http://home.netscape.com/newsref/std/cookie_spec.html</a>
- </pre>
-
- <p>The <font size="-1">CGI</font> module provides support for
- managing cookies. See <a href=
- "#What_CGI_modules_run_with_Perl_f">What CGI modules run with
- Perl for Win32?</a> for information about the <font size="-1">
- CGI</font> module, including the location of online
- documentation.</p>
- <br />
- <hr />
-
- <h2><a name="How_do_I_get_the_e_mail_address_">How do I get the
- e-mail address of the user?</a></h2>
-
- <p>It's not, in general, possible to get the e-mail address of
- a user without asking them for it. If you need an e-mail
- address, provide the user with a form to fill in an
- address.</p>
-
- <p>The <font size="-1">HTTP</font> specification (see <a href=
- "#What_is_HTTP_and_how_do_I_get_m">What is HTTP, and how do I
- get more information on it?</a>) defines an <font size="-1">
- HTTP</font> request header field, <code>From:</code>, that can
- contain the e-mail address of the user making the connection.
- Your script can retrieve it using the environment variable
- <font size="-1">HTTP_FROM.</font> However, it's rarely provided
- and can't really be counted on.</p>
-
- <p>There are all kinds of sneaky ways to determine where
- requests come from -- like checking the <font size="-1">
- IP</font> address that was used to connect -- but you can't
- figure out the e-mail address of the user this way.</p>
-
- <p>Generally, it's considered a violation of the user's privacy
- to get their e-mail address without their knowledge. Perhaps
- that's why it's so difficult.</p>
- <br />
- <hr />
-
- <h2><a name="I_need_a_CGI_script_to_do_a_cert">I need a CGI
- script to do a certain task. Has anyone done it
- before?</a></h2>
-
- <p>There are several <font size="-1">CGI</font> script archives
- on the web. You may not be able to find exactly the script you
- want, but you will probably find something that can be adapted
- to your needs.</p>
-
- <p>A well known script page is:</p>
-
- <ul>
- <li>
- <p>Selena Sol's Script Archive: <a href=
- "http://www.extropia.com/Scripts/">
- http://www.extropia.com/Scripts/</a></p>
- </li>
- </ul>
-
- <p>Note that most script archives have UNIX-targeted scripts,
- and you may have to make some adaptations to them to make them
- run (see <a href=
- "perlwin32faq5.html#How_do_I_make_a_UNIX_based_scrip">How do I
- make a UNIX-based script work?</a>).</p>
-
- <p>This is one of the most common questions on the
- Perl-Win32-Users list. Occasionally it's phrased more like
- <font size="-1">``I</font> have a program to write. Here are
- the specs. Please e-mail it to me by Friday.'' Hopefully the
- reader can understand why these messages are usually answered
- rudely, if they are answered at all.</p>
- <br />
- <hr />
-
- <h2><a name="How_do_I_test_my_CGI_programs_th">How do I test my
- CGI programs that take arguments without running them through
- the web server?</a></h2>
-
- <p>The hard way to test your <font size="-1">CGI</font>
- programs from the command line is to set up environment
- variables and a standard input stream just like a web server
- would (see the <font size="-1">CGI</font> 1.1 specification for
- more details on this -- see <a href=
- "#What_is_CGI_and_how_do_I_get_mo">What is CGI, and how do I
- get more information on it?</a>).</p>
-
- <p>The easy way is to use <code>CGI.pm</code>, the Perl module
- for <font size="-1">CGI</font> programming. It provides an easy
- mechanism to run <font size="-1">CGI</font> programs, with
- arguments, from the command line. See <a href=
- "#What_CGI_modules_run_with_Perl_f">What CGI modules run with
- Perl for Win32?</a>.</p>
- <br />
- <hr />
-
- <h2><a name="The_Content_Type_header_field_I">The Content-Type:
- header field I output from my CGI script shows up in the web
- browser.</a></h2>
-
- <p>You are using an older version of Perl for <font size="-1">
- ISAPI</font> as your Perl interpreter on an <font size="-1">
- IIS</font> web server, but it's not outputting an <font size=
- "-1">HTTP</font> status line. You should be able to fix this by
- installing the most recent version of Perl and PerlIS. See <a
- href="#My_CGI_scripts_don_t_seem_to_run">My CGI scripts don't
- seem to run right under Perl for ISAPI.</a> for more
- details.</p>
- <br />
- <hr />
-
- <h2><a name="When_I_try_to_run_a_CGI_script_f">When I try to
- run a CGI script from my browser, it tries to download a file
- of type "application/x-perl" instead.</a></h2>
-
- <p>Your web server has been misconfigured. It doesn't know that
- it should execute your Perl program, so it's just returning it
- to the browser. See <a href="perlwin32faq6.html#">the
- perlwin32faq6 manpage</a> for details on how to configure your
- particular web server to know that Perl scripts should be
- executed.</p>
- <br />
- <hr />
-
- <h2><a name="What_s_Perl_for_WSAPI_">What's Perl for
- WSAPI?</a></h2>
-
- <p>Perl for <font size="-1">WSAPI,</font> or PerlWS for short,
- offers the same functionality as Perl for <font size="-1">
- ISAPI</font> to users of O'Reilly's WebSite Professional web
- server.</p>
- <br />
- <hr />
-
- <h1><a name="AUTHOR_AND_COPYRIGHT">AUTHOR AND
- COPYRIGHT</a></h1>
-
- <p>This <font size="-1">FAQ</font> was originally assembled and
- maintained by Evangelo Prodromou. <a href=
- "mailto:evangelo@endcontsw.com">evangelo@endcontsw.com.</a> It
- has been revised and updated by Brian Jepson of O'Reilly and
- Associates, and David Grove and David Dmytryshyn of
- ActiveState.</p>
-
- <p>This <font size="-1">FAQ</font> is in the public domain. If
- you use it, however, please ensure that you give credit to the
- original authors.</p>
-
- <p><!-- beginning of leaf footer--></p>
-
- <table width="100%">
- <tr>
- <td bgcolor="000000" width="70" height="31"><a href=
- "http://www.activestate.com/"><img src="ASbutton.gif" alt=
- "ActiveState Home Page" border="0" width="68" height=
- "30" /></a></td>
-
- <td width="10"> </td>
-
- <td valign="middle" bgcolor="#cc0066"><font face=
- "sans-serif" size="+1" color="#ff99cc">
- Win32 FAQ</font></td>
- </tr>
- </table>
- <!-- end of leaf footer-->
- </body>
- </html>
-
-