[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Getting started with CGI



<Common Questions>

>Hi,
>
>I am rather new to MacPerl and trying to understand how CGI-Scripting 
>works. I understood that you can send your data to the script in a URL 
>like this: <http://www.xy.com/cgi/test.pl?search=bla>. But how can I make 
>the perl script catch the parameter string? Is there a short answer to 
>this question (I don't expect anyone to write a novel)? If not, can 
>someone point me to a good description of the mechanism?
Include this sub from PerlSlinger A3 in your code:

sub MoreSecureFormParser
{ #by Chilton Webb chilton@devhq.com
#this even patches up the semicolon security hole on Unix boxes. 
#Call like this:
#&MoreSecureFormParser(*in);
#$myVariable = $in{'searchstring'}; #etc.
local (*qs) = @_ if @_;

  if ($ENV{'REQUEST_METHOD'} eq "GET") {$qs = $ENV{'QUERY_STRING'};}
  elsif ($ENV{'REQUEST_METHOD'} eq "POST")
     {read(STDIN,$qs,$ENV{'CONTENT_LENGTH'});}

  @qs = split(/&/,$qs);
  foreach $i (0 .. $#qs)
  {
     $qs[$i] =~ s/\+/ /g;
     $qs[$i] =~ s/\;/ /g;
     $qs[$i] =~ s/\%3B/ /g;
     $qs[$i] =~ s/%(..)/pack("c",hex($1))/ge;
     ($name,$value) = split(/=/,$qs[$i],2);
     if($qs{$name} ne "") {$qs{$name} = "$qs{$name}:$value";}
     else {$qs{$name} = $value;}
  }
  return 1;
}

----
At this point, if you've got a form text box named "SearchIt", for 
example, you'd find the entered string in $in{'SearchIt'}
Does that make sense?

>
>One more question: How can I set up a lokal environment on my Mac that 
>acts like a Browser-Server-Interaction over the Internet? In other words, 
>how can I get my collection of HTML-files and CGI-scripts to work lokally 
>(for testing- and other purposes)? 
Take a look at NW 59 - Standalone Networking (15-March-1999) at Apple.com.

-Chilton

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org