2022年Perl语言高级编程专题 .pdf
Pomeftp.orgSpring, 20071Perl语言高级编程专题Lesson 14周晓方coursesxfzhou.homeftp.orgerlcoursesxfzhou.hSpring, 20072Web browser & Http Server1.User opens browser and enters a target address2.Browser connects to the server (on port 80), and sends request3.Server finds the web page and returns it with HTTP header.4.If not found, server returns an error message.5.Browser transforms the reply and display to user.ClientServerGET /index.htm HTTP /1.0HTTP /1.0 200 OK HTTP /1.0 404 Not Found?Try these:telnet 80type GET / HTTP /1.0, with 2 ENTERstelnet 25telnet 110名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 12 页 - - - - - - - - - Pomeftp.orgSpring, 20073Web Server & CGI Perl1.User opens browser and enters a target address2.Browser connects to the server (on port 80), and sends request3.Server setups CGI environment and starts the Perl CGI script. After script terminals, server collects and returns the result.4.If Perl CGI script not found, server returns an error message.5.Browser transforms the reply and display to user.+The web page is dynamic, not static+Perl/CGI is almost platform independent (v.s. ASP etc) +Client browser is simple (v.s. client side scripts)-Speed may be slower if server is slow (v.s. ASP).ClientServerGETHTTPCGIPerl CGI scripterlcoursesxfzhou.hSpring, 20074Install a local Web Server? Check if tcp/ip protocol is installed on your PC? xitami free web server ()xitami/Pro 是带 SSL的xitami http:/ Install the GUI version of web server? Setuphttp:/localhost/admin? home of webpage: /xitami/webpages? home of cgi scripts: /xitami/cgi-bin? home of ftp root: /xitami/ftproot/?/? test server: http:/localhost/? test cgi: http:/localhost/cgi-bin/testcgi名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 12 页 - - - - - - - - - Pomeftp.orgSpring, 20075Write a 1st Web Page? Add following lines to /webpages/home.htm? Open IE & links to http:/localhost/home.htmMy 1st Web PageHay! Welcome to my homepage!Still underconstruction.TimeHay! Welcome to my homepage!Still under construction. Timeerlcoursesxfzhou.hSpring, 20076Write a 1st CGI-Perl script? Add these lines to/cgi-bin/time.pl? Click the Timelink, and runs thescript on server.#!/usr/bin/perl -wuse strict;my $time = localtime();print HERE;Content-type: text/htmlWhats the time?Current time is$timeBackHERE1;Current time isSun Nov 9 08:17:07 2003Back名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 12 页 - - - - - - - - - Pomeftp.orgSpring, 20077Xitami Server Hints? 公网网站一定要拿 ICP号http:/ 尽量避免开设论坛、博客、新闻等内容? 解包xiopen_2_5.zip后可直接运行GUI / Console / Server / Control panel 版本? 设置文件需要简单认证的网页口令和密码:xitami.aut网站和虚拟网站的设置:default.cfg, *.cfg? 配置方法:打开 admin口,进入 http:/127.0.0.1/admin? 什么是 SSL(网页过滤功能 ):看一下 perlssi脚本? 怎么调试 CGI:查看 cgierr.log? 在一台主机上建立多个虚拟网站分目录, 绑定不同 的ip地址,绑定不同 的域名? 提示:安装路径 和perl路径不 要包含空格erlcoursesxfzhou.hSpring, 20078HTML formats & tags? Tags: v.s. Container tags: , .Empty tag, open tag, or one-time tag: , , Tag with arguments: ? White spaces o Single space (with exceptions)? Special symbols (& is the escape-char in html):  or  , an non-breaking-space< (), & (& itself), &pi ( p), © or © ( ), ® (), ¥ (¥ )? 非frame的网页? Frame的网页 框架(用 notepad看一下 c:/perl/html/index.html )名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 12 页 - - - - - - - - - Pomeftp.orgSpring, 20079Inside a section? , add a title on browser不宜过长? 显示中 文? sample: 周晓方 复旦大学 开课相关 网页 ? Good style Add comments in head section:erlcoursesxfzhou.hSpring, 200710Headings and paragraphs? ? Paragraphs: A paragraph.The is optional with align=?: with nowrap: ? Adding line brakes: ? Preformatedparagraphs:White spaces are significant inside ? horizontal bar: width= pixelswidth= percent%size=pixelsalign=centeralign=leftalign=rightcolor=#rrggbbcolor=red/green/lightblue/darkgray 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 12 页 - - - - - - - - - Pomeftp.orgSpring, 200711Text formatting? Bold粗体字 Italic 斜体下划线 划线? 大号字体 小号.? 字体.? 下标上标? 逻辑字体加重 等宽, .变量erlcoursesxfzhou.hSpring, 200712Listing? ordered list:Apply projectSign contract & budgetHardworkingCheck point? unordered list:Leaser Jet 6LLeaser Jet 1010cheeperfaster1. Apply project 2. Sign contract & budget 3. Hardworking 4. Check point?Leaser Jet 6L ?Leaser Jet 1010 cheeper faster 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 12 页 - - - - - - - - - Pomeftp.orgSpring, 200713Link?Link to other web pagesMy home pageBack to homeGoogleWhats the time now.?Link to named tagSection 1:Goto section 1Goto Sec 1 of Ch2?Open link in new windowsHere?Invoke your mail clientMeerlcoursesxfzhou.hSpring, 200714Table? ? ? row:? head cell: ? data cell: Team Statistics PlayerGoalsAssistsPoints Anne71219 Eric41115Team Statistics PlayerGoals Assists PointsAnne71219Eric41115名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 12 页 - - - - - - - - - Pomeftp.orgSpring, 200715Image? Image format: GIF and JPEGGIF: 256 color compressed, LZ-compressJPEG: True color compressed, DCT+Huffman? width= pixelhight=pixelalt=description textborder=pixelvspace=pixelhspace=pixelalign=top/middle/bottom/left/right? Image as Bullet CharactersItem 1Item 2Item 3 erlcoursesxfzhou.hSpring, 200716Frames? ? ? Inside index.html Inside toc.htmChapter1Chapter2banner.htmtoc.htmChapter1Chapter2main windowchapter1.htmchapter2.htm名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 12 页 - - - - - - - - - Pomeftp.orgSpring, 200717HTML Forms 发送、接收表 单信息? Client side: action=protocol:/server/path/script/extra_path_infoGET(default): append all encoded data at the end of URLPOST: sends data to server in a separate HTTP transaction? Server side (method=GET) CGI:Receive encoded data in $ENVQUERY_STRINGUse STDOUT to return dataData cant be too long. Usually 1K bytes? Server side (method=POST) CGI:Receive encoded data from STDIN. Note: no EOF at end!use $ENVCONTENT_LENGTHto determine the data sizeUse STDOUT to return dataerlcoursesxfzhou.hSpring, 200718Usefull CGI ENV VariablesName of the server software (Xitami)SERVER_SOFTWAREPort # of the server (default is 80)SERVER_PORTDomain name or IP of the serverSERVER_NAMEVirtual path of the scriptSCRIPT_NAMEGET or POSTREQUEST_METHODauthenticated remote user nameREMOTE_USERname of the remote computerREMOTE_HOSTIP address of remote computerREMOTE_ADDRencoded dataGETQUERY_STRINGphysical path/script/extra_path_infoPATH_TRANSLATEDextra path information stringPATH_INFOlength in byte of encoded dataPOSTCONTENT_LENGTHDescriptionMethodVariable名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 12 页 - - - - - - - - - Pomeftp.orgSpring, 200719TEXT, PASSWORD, TEXTAREA? A single line of text (user-name, phone #, etc)SIZE: the windows width show on browserMAXLENGTH can be larger then SIZE (scrolling)? A single line of password (password)Display * when you typing in PASSWORD lineText is not encrypted when sending to server. Better use with POST method.? Multiply lines of text (email body, etc)default textSince the size of text inputed is usually unlimited, youd better use TEXTAREA with POST methodName*erlcoursesxfzhou.hSpring, 200720Action buttons, Image buttons? Action buttons, SUBMIT and RESETDont include multiply SUBMIT or RESET button in one simple form? Image button sends co-ordinates!Same function as SUBMIT buttonreturn LOGO.x=?&LOGO.y=? in dataleft-top corner is (0,0)SendClear名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 12 页 - - - - - - - - - Pomeftp.orgSpring, 200721Buttons, Radio or Check Boxes? Radio button, choose one from manygrouped radios shall share the same name智商 <8080-120>120性别 保密男女? Check boxes, on-&-off styleEachshall have a different namePerlJavaCVerilogPerl Java C Verilog C1=1&C3=1&C4=1智商120 性别保密男女IQ=B&GE=Berlcoursesxfzhou.hSpring, 200722SELECT/OPTION单选或多选的列表? 单选 ? 多选 ? 选项 内容 内容DOSWindowsLinux小学中学大学Windowsplatform=Windows&options=%D6%D0%D1%A7&options=%B4%F3%D1%A7小学中学大学名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 11 页,共 12 页 - - - - - - - - - Pomeftp.orgSpring, 200723Encoding, etc? HIDDEN, send contextual data? Encoding in GET methodURL_in_action . ? . name=val&name=valspace converted to +special chars (like +) converted to %?, ? is the heximal ASCII value of the char. e.g.+ %2B% %25计算机%BC%C6%CB%E3%BB%FAerlcoursesxfzhou.hSpring, 200724POST method and Decoding? Useful Environment Variables:REQUEST_METHOD & CONTENT_LENGTH? Data parsing and decoding:$DataLen = $ENVCONTEXT_LENGTH;#获得数据长度read(STDIN, $QueryString, $DataLen);#读入指定长度NameValuePairs = split(/&/, $QueryString);foreach $NameValue (NameValuePairs) ($Name, $Value) = split(/=/, $NameValue);$Value = tr/+/ /;#恢复空格$Value = s/%(dA-Fa-f2)/pack(C,hex($1)/eg;#恢复 %? 编码的字符print Name = $Name, Value = $Valuen;名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 12 页,共 12 页 - - - - - - - - -