X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlfaq9.pod;h=d1bd593dfe7690c16f2a977b086d5e302a7eb48b;hb=2aa761807d7eac561ade382b2c66eebffcdf056f;hp=d7faca02e316951b7ebc8ab92775ff6a5eb5e7a2;hpb=bfd13ef816abf16369321d26f2f63772eff5cd21;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlfaq9.pod b/pod/perlfaq9.pod index d7faca0..d1bd593 100644 --- a/pod/perlfaq9.pod +++ b/pod/perlfaq9.pod @@ -1,40 +1,88 @@ =head1 NAME -perlfaq9 - Networking ($Revision: 1.16 $, $Date: 1997/04/23 18:12:06 $) +perlfaq9 - Networking ($Revision: 1.26 $, $Date: 1999/05/23 16:08:30 $) =head1 DESCRIPTION This section deals with questions related to networking, the internet, and a few on the web. -=head2 My CGI script runs from the command line but not the browser. Can you help me fix it? +=head2 My CGI script runs from the command line but not the browser. (500 Server Error) -Sure, but you probably can't afford our contracting rates :-) +If you can demonstrate that you've read the following FAQs and that +your problem isn't something simple that can be easily answered, you'll +probably receive a courteous and useful reply to your question if you +post it on comp.infosystems.www.authoring.cgi (if it's something to do +with HTTP, HTML, or the CGI protocols). Questions that appear to be Perl +questions but are really CGI ones that are posted to comp.lang.perl.misc +may not be so well received. -Seriously, if you can demonstrate that you've read the following FAQs -and that your problem isn't something simple that can be easily -answered, you'll probably receive a courteous and useful reply to your -question if you post it on comp.infosystems.www.authoring.cgi (if it's -something to do with HTTP, HTML, or the CGI protocols). Questions that -appear to be Perl questions but are really CGI ones that are posted to -comp.lang.perl.misc may not be so well received. +The useful FAQs and related documents are: -The useful FAQs are: + CGI FAQ + http://www.webthing.com/tutorials/cgifaq.html - http://www.perl.com/perl/faq/idiots-guide.html - http://www3.pair.com/webthing/docs/cgi/faqs/cgifaq.shtml - http://www.perl.com/perl/faq/perl-cgi-faq.html - http://www-genome.wi.mit.edu/WWW/faqs/www-security-faq.html - http://www.boutell.com/faq/ + Web FAQ + http://www.boutell.com/faq/ + + WWW Security FAQ + http://www.w3.org/Security/Faq/ + + HTTP Spec + http://www.w3.org/pub/WWW/Protocols/HTTP/ + + HTML Spec + http://www.w3.org/TR/REC-html40/ + http://www.w3.org/pub/WWW/MarkUp/ + + CGI Spec + http://www.w3.org/CGI/ + + CGI Security FAQ + http://www.go2net.com/people/paulp/cgi-security/safe-cgi.txt + +=head2 How can I get better error messages from a CGI program? + +Use the CGI::Carp module. It replaces C and C, plus the +normal Carp modules C, C, and C functions with +more verbose and safer versions. It still sends them to the normal +server error log. + + use CGI::Carp; + warn "This is a complaint"; + die "But this one is serious"; + +The following use of CGI::Carp also redirects errors to a file of your choice, +placed in a BEGIN block to catch compile-time warnings as well: + + BEGIN { + use CGI::Carp qw(carpout); + open(LOG, ">>/var/local/cgi-logs/mycgi-log") + or die "Unable to append to mycgi-log: $!\n"; + carpout(*LOG); + } + +You can even arrange for fatal errors to go back to the client browser, +which is nice for your own debugging, but might confuse the end user. + + use CGI::Carp qw(fatalsToBrowser); + die "Bad error here"; + +Even if the error happens before you get the HTTP header out, the module +will try to take care of this to avoid the dreaded server 500 errors. +Normal warnings still go out to the server error log (or wherever +you've sent them with C) with the application name and date +stamp prepended. =head2 How do I remove HTML from a string? -The most correct way (albeit not the fastest) is to use HTML::Parse -from CPAN (part of the libwww-perl distribution, which is a must-have -module for all web hackers). +The most correct way (albeit not the fastest) is to use HTML::Parser +from CPAN. Another mostly correct +way is to use HTML::FormatText which not only removes HTML but also +attempts to do a little simple formatting of the resulting plain text. Many folks attempt a simple-minded regular expression approach, like -C.*?E//g>, but that fails in many cases because the tags +C<< s/<.*?>//g >>, but that fails in many cases because the tags may continue over line breaks, they may contain quoted angle-brackets, or HTML comment may be present. Plus folks forget to convert entities, like C<<> for example. @@ -49,6 +97,29 @@ program in http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/striphtml.gz . +Here are some tricky cases that you should think about when picking +a solution: + + A > B + + A > B + + + + + + <# Just data #> + + >>>>>>>>>>> ]]> + +If HTML comments include other tags, those solutions would also break +on text like this: + + + =head2 How do I extract URLs? A quick but imperfect approach is @@ -62,12 +133,11 @@ A quick but imperfect approach is }gsix; This version does not adjust relative URLs, understand alternate -bases, deal with HTML comments, deal with HREF and NAME attributes in -the same tag, or accept URLs themselves as arguments. It also runs -about 100x faster than a more "complete" solution using the LWP suite -of modules, such as the -http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/xurl.gz -program. +bases, deal with HTML comments, deal with HREF and NAME attributes +in the same tag, understand extra qualifiers like TARGET, or accept +URLs themselves as arguments. It also runs about 100x faster than a +more "complete" solution using the LWP suite of modules, such as the +http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/xurl.gz program. =head2 How do I download a file from the user's machine? How do I open a file on another machine? @@ -78,7 +148,7 @@ the same as the startform() method. =head2 How do I make a pop-up menu in HTML? -Use the BSELECTE> and BOPTIONE> tags. The CGI.pm +Use the B<<