[ Pobierz całość w formacie PDF ]
.} operator.ARGV will be the filehandle for each file as it is read through the while(){.} operator.SummaryIn this chapter, you learned that there are three types of environment variables; the ones you get at the command line, within your CGIprogram, and for SSI commands are each different.This happens because the scope of environment variables is at the process level, and theprocess environment is different for each.You learned that scope defines the area within which a variable can be used and that you can limit the scope of a variable to the enclosingcode block (enclosed in curly braces) by using the Perl local function.This chapter discussed the two types of CGI environment variables: the server environment variables and the environment variables basedon HTTP request headers.The server environment variables always are available for your CGI program, but the set of HTTP requestheader environment variables differs with every client connection.This chapter also covered how you can use the HTTP request header environment variables to get a lot of information about each visitor toyour Web site, but getting the name of that visitor often is difficult.Finally, you learned that the Netscape cookie is an excellent means ofmaintaining information about each client who connects to your Web site.Q&AQ In this chapter, you told us about the Path environment variable issued for searching for programs.In the last chapter, yousaid this was done with the @Inc array.What gives?A Would you believe me if I told you that I told you the truth both times? Well, I did.The difference is who or what is doing the looking.The @Inc array is another of Perl's special variables, so it must be used by Perl.And, of course, it is.It is used only when you use therequire function.The require function tells Perl to add whatever Perl code is in the require parameter list to the list of code itwill execute.The require command only uses the list of directories in the @Inc array as a search path.But when you try to execute asystem or another CGI program from within your CGI program, the Path variable is used by the UNIX operating system to search forthe system command you requested.Q If I modify my environment variables, will they be there when I try to use them the next time?A No.Environment variables have process scope.This means that they are available to every executing program within that process.Assoon as your CGI program stops executing, however, the process that enclosed it ends.So any environment variables that you set endwith that process.When your CGI program is started again, even if from exactly the same connection, an entire new process is startedwith an entire new set of environment variables.http://docs.rinet.ru:8080/CP7/ch6.htm (23 of 23) [2/17/2007 2:08:00 PM]http://docs.rinet.ru/CP7/f3-4.gifhttp://docs.rinet.ru/CP7/f3-4.gif [2/17/2007 2:08:05 PM]http://docs.rinet.ru/CP7/f3-5.gifhttp://docs.rinet.ru/CP7/f3-5.gif [2/17/2007 2:08:07 PM]http://docs.rinet.ru/CP7/f3-6.gifhttp://docs.rinet.ru/CP7/f3-6.gif [2/17/2007 2:08:12 PM]Ebook banner rotater for Web Programming and AdministrationTeach Yourself CGIProgramming with PERL5 in a Week, 2Eby Eric HerrmannC O N T E N T SIntroductionChapter 1 An Introduction to CGI and ItsEnvironmentThe Common Gateway Interface (CGI)HTML, HTTP, and Your CGI ProgramThe Role of HTMLThe HTTP HeadersYour CGI ProgramThe Directories on Your ServerThe Server RootThe Document RootFile Privileges, Permissions, and ProtectionWWW ServersMS-Based ServersThe CERN ServerThe ncSA Serverhttp://docs.rinet.ru:8080/CP7/index.htm (1 of 18) [2/17/2007 2:08:39 PM]Ebook banner rotater for Web Programming and AdministrationThe Netscape ServerThe CGI Programming ParadigmCGI Programs and SecurityThe Basic Data-Passing Methods of CGICGI's Stateless EnvironmentPreventing the Most Common CGI BugsTell the Server Your File Is ExecutableFinding Things on Your SystemMake Your Program ExecutableLearning PerlHello WorldExercise 1.1.Working with Perl variablesExercise 1.2.Using the scalar variableSummaryQ&AChapter 2 Understanding How the Server andBrowser CommunicateUsing the Uniform Resource IdentifierThe ProtocolThe Domain NameThe Directory, File, or CGI ProgramRequesting Your Web Page with the BrowserUsing the Internet ConnectionTCP/IP, the Public Socket, and the PortOne More Time, Using the Switchboard AnalogyUsing the HTTP HeadersStatus Codes in Response HeadersThe Method Request HeaderThe Full Method Request HeaderThe Accept Request HeaderThe HTTP Response HeaderChanging the Returned Web Page Based on the User-Agent Headerhttp://docs.rinet.ru:8080/CP7/index.htm (2 of 18) [2/17/2007 2:08:39 PM]Ebook banner rotater for Web Programming and AdministrationLearning PerlExercise 2.2.Using the Perl regular arrayExercise 2.3.Using Perl's associative arraySummaryQ&AChapter 3 Using Server Side Include CommandsUsing SSI NegativesUnderstanding How SSIs WorkDeciding Whether to Enable SSIsUsing the Options DirectiveUsing the AddType Command for SSIsUsing the srm.conf FileAutomatically Adding the Last Modification Date to Your PageExamining the Full Syntax of SSI CommandsUsing the SSI config CommandUsing the include CommandAnalyzing the include CommandUsing the virtual Command ArgumentUsing the file Command ArgumentExamining the flastmod CommandThe Syntax of the SSI echo CommandThe exec Command and CGI ScriptsLooking At Security Issues with SSIsLearning PerlExercise 3.2.The Perl conditional statement if(){} else{}SummaryQ&AChapter 4 Using Forms to Gather and Send DataUnderstanding HTML Form TagsUsing the HTML Form Method AttributeThe Get and Post Methodshttp://docs.rinet.ru:8080/CP7/index.htm (3 of 18) [2/17/2007 2:08:39 PM]Ebook banner rotater for Web Programming and AdministrationThe Get MethodThe Post MethodGenerating Your First Web Page On-the-FlyComparing CGI Web Pages to HTML FilesAnalyzing first.cgiSending Variables in Your CGI ProgramUsing the HTML Input TagSending Data to Your CGI Program with the Text FieldUsing the Submit Button to Send Data to Your CGI ProgramMaking Your Text-Entry Form Fast and Professional LookingNPH-CGI ScriptsNPH-CGI Scripts Are FasterURI-Encoded Data Ends Up in the Location WindowSeeing What Happens to the Data Entered on Your FormName/Value PairsPath InformationUsing URI EncodingReserved CharactersThe Encoding StepsLearning PerlThe Perl for StatementThe Perl foreach StatementSummaryQ&AChapter 5 Decoding Data Sent to Your CGIProgramUsing the Post MethodUsing Radio Buttons in Your Web Page Forms and ScriptsThe HTML Radio Button FormatThe Name AttributeThe Value AttributeThe Checked Attributehttp://docs.rinet.ru:8080/CP7/index.htm (4 of 18) [2/17/2007 2:08:39 PM]Ebook banner rotater for Web Programming and AdministrationRadio Button RulesReading and Decoding Data in Your CGI ProgramUsing the ReadParse FunctionCreating Name/Value Pairs from the Query StringDecoding the Name/Value PairsUsing the Post MethodUsing the Perl read FunctionIncluding Other Files and Functions in Your CGI ProgramsUsing the Data Passed with Radio ButtonsUsing Perl's If Elsif BlockUsing the HTML CheckboxUsing a Database with Your CGI ProgramUsing Pull-Down Menus in Your Web Page Forms and ScriptsUsing the HTML Form Select TagUsing the Option FieldUsing File Data in Your CGI ProgramOpening a FileReading Formatted DataUsing Formatted File DataUsing Data to Make Your CGI Programming EasierLearning PerlExercise 5.2
[ Pobierz całość w formacie PDF ]