Axil S/E kdk018
				  1997. 4. 16.
				  Kim Do Kyung

SUBJECT: À¥¼­¹ö¿¡ ¹æ¸í·Ï(Guestbook)  ¸¸µé±â

DESCRIPTION:

¡Ú À¥¼­¹ö¿¡ ¹æ¸í·Ï ¸¸µé±â

	¡Ø ¹æ¸í·Ï È­ÀÏ

  ½ÇÁ¦ ¹æ¹®ÇÑ »ç¶÷µéÀÇ ±â·ÏÀÌ ÀÌ È­ÀÏ¿¡ ³²°Ô µÈ´Ù.

### guestbook.html ### 

 
    ¹æ¸í·Ï 



¹æ¸í·Ï...

»õ·Î¿î ¹æ¸í·ÏÀ» ÀÛ¼ºÇϽ÷Á¸é ¿©±â¸¦ Ŭ¸¯Çϼ¼¿ä.


¡Ø ¹æ¸í·ÏÀ» ÀÛ¼ºÇÏ´Â È­ÀÏ ÀÌ È­ÀÏ¿¡¼­ ¹æ¸í·Ï CGI ProgramÀ» CallÇÏ°Ô µÈ´Ù. ### addbook.html ### ¹æ¸í·Ï ÀÛ¼º

¹æ¸í·Ï ÀÛ¼º



Name       
Email      
Comments   

¡Ø ¹æ¸í·Ï CGI Program ¹æ¸í·Ï CGI Script·Î ¸ðµç ¹æ¸í·Ï ÇÁ·Î±×·¥ÀÇ ±Ù°£À̶ó ÇÒ ¼ö ÀÖ´Ù. #!/usr/local/bin/perl $mesgfile = "../htdocs/guestbook.html"; <= /cgi-bin ¿¡ guestbook.plÀÌ ÀÖÀ½À» ¾Ë ¼ö ÀÖ´Ù. $DATE = `date +%y/%m/%d`; <= "³âµµ/¿ù/ÀÏ"ÀÇ Çü½ÄÀ¸·Î Ãâ·Â # HTML¹®¼­ÀÇ FORM¿¡¼­ ³Ñ°Ü¹ÞÀº °ªÀ» ºÐ¸®ÇØ ³½´Ù. if ($ENV{'REQUEST_METHOD'} eq "GET") { <= ¿©±â¼­ºÎÅÍ .... $FORM_DATA = $ENV{'QUERY_STRING'}; } else { $LENGTH = $ENV{'CONTENT_LENGTH'}; while($LENGTH) { $FORM_DATA .= getc(STDIN); $LENGTH--; ÀÌ °÷Àº ´Ù¸¥ CGI¿¡¼­µµ ÀÀ¿ëÇÒ ¼ö ÀÖ´Ù. } guestbook.plÀ» È£ÃâÇÒ¶§ÀÇ parameter passing } URLÀÌ guestbook.pl?name=KDK&email=kdk@hyundai&... ÀÌ·¸°Ô µÇ¹Ç·Î &¿Í ?¸¦ ÀÌ¿ëÇØ DATA¸¦ parsingÇÏ´Â ºÎºÐÀÌ´Ù. foreach (split(/&/, $FORM_DATA)) { ($NAME, $VALUE) = split(/=/, $_); $NAME =~ s/\+/ /g; $NAME =~ s/%([0-9|A-F]{2})/pack(C, hex($1))/eg; $VALUE =~ s/\+/ /g; $VALUE =~ s/%([0-9|A-F]{2})/pack(C, hex($1))/eg; $FORM{$NAME} = $VALUE; <= ¿©±â±îÁö ... } ######################### # Get Variables ######################### $name = $FORM{'name'}; <= Standard InputÀ» ÅëÇØ µé¾î¿Â º¯¼öµéÀ» ÇÁ·Î±×·¥ $email = $FORM{'email'}; ¿¡¼­ »ç¿ëÇÒ º¯¼ö·Î ´ëÀÔÇÑ´Ù. $comment = $FORM{'comment'}; ######################### # ¹æ¸í·Ï¿¡ Ãß°¡ ######################### open (MAIN, "$mesgfile") || die $!; <= $mesgfileÀ» ¿ÀÇÂÇØ mainÀ̶ó´Â Array¿¡ @main =
; ¸ðµç ¶óÀÎÀ» ÀúÀåÇØ µÐ´Ù. close(MAIN); open (MAIN, "> $mesgfile") || die $!; <= $mesgfileÀ» ¾²±â ¸ðµå·Î ¿ÀÇ foreach $main_line (@main) { if ($main_line =~ //) { <= beginÀÌ ÀÖ´Â ¶óÀο¡ »ðÀÔ(»õ·Î¿î³»¿ë) print MAIN "\n"; print MAIN "$name\n"; print MAIN "$DATE
\n"; print MAIN "$comment

\n"; } else { print MAIN "$main_line"; } } ######################### # º¸¿© ÁÖ±â ######################### print "Content-type: text/html\n\n"; <= HTML¹®¼­ÀÓÀ» Client¿¡°Ô ¾Ë·ÁÁØ´Ù. open (MAIN, "$mesgfile") || die $!; <= »õ·Î¿î ¶óÀÎÀÌ Ãß°¡µÈ $mesgfile À» Ãâ·Â while (
) { print "$_"; } close (MAIN);