Thursday 6 July 2017

Cgi ไบนารี ตัวเลือก


ข้อสงวนสิทธิ์: ตัวเลือกไบนารีและการซื้อขายแลกเปลี่ยนมีความเสี่ยง รูปแบบธุรกิจและรายได้: ผลการค้นหาจะขึ้นอยู่กับการเลือกทิศทางของราคาทรัพย์สินจากราคาการตีราคาที่กำหนดตามระยะเวลาที่เลือกไว้ เมื่อเริ่มต้นการค้าผู้ค้าจะได้รับหน้าจอยืนยันการแสดงเนื้อหาราคาตีราคาทิศทางที่เลือก (CALL หรือ PUT) และจำนวนเงินลงทุน เมื่อได้รับข้อความแจ้งจากหน้าจอนี้การค้าจะเริ่มต้นภายใน 3 วินาทีเว้นแต่ผู้ค้าจะกดปุ่มยกเลิก TRBinaryOptions เสนอตัวเลือกที่เร็วที่สุดหมดอายุสำหรับสาธารณะและการทำธุรกรรมสามารถทำได้เร็วถึง 15 นาทีในตัวเลือกไบนารีปกติและเร็วที่สุดเท่า 60 วินาทีในแพลตฟอร์ม 60 วินาที แม้ว่าความเสี่ยงในการซื้อขายไบนารีตัวเลือกจะถูกกำหนดสำหรับการค้าแต่ละครั้งการค้าที่มีชีวิตอยู่และเป็นไปได้ที่จะสูญเสียการลงทุนเริ่มต้นโดยเฉพาะอย่างยิ่งถ้าผู้ประกอบการค้าเลือกที่จะวางการลงทุนทั้งหมดของเขาเพื่อการค้าสดเดียว ขอแนะนำให้ผู้ค้าเลือกกลยุทธ์การบริหารจัดการเงินที่ถูกต้องซึ่งจะ จำกัด การซื้อขายรวมกันทั้งหมดหรือยอดเงินลงทุนคงค้างทั้งหมด ขอแนะนำให้ใช้เบราเซอร์ Mozilla Firefox หรือ Google Chrome เมื่อซื้อขาย TRBinaryOptions ขอบคุณสำหรับความสนใจของคุณ 7 ตัวเลือกไบนารี 7 ตัวเลือกไบนารีวิธีการสร้างรายได้ออนไลน์ด้วยการซื้อขายตัวเลือกไบนารีตั้งแต่ปี 2008 การลงทุนและการทำเงินออนไลน์ด้วยตัวเลือกไบนารีได้กลายเป็นที่สนใจมากขึ้นสำหรับนักลงทุนและบุคคลที่ลงทุนในหุ้น หุ้น, สกุลเงินและสินค้าโภคภัณฑ์ มีเพียงสองตัวเลือกในการซื้อขายไบนารีเพราะฉะนั้นการใช้ไบนารีคำ เกือบจะเหมือนกับการวางเดิมพันเนื่องจากคุณกำลังพนันว่าสินทรัพย์จะเพิ่มหรือลดมูลค่าในช่วงเวลาที่กำหนดไว้ การค้าไบนารีมีตัวเลือกสำหรับตลาดในการควบคุมตนเองและมีโอกาสที่จะควบคุมหุ้นที่ถูกล่วงเกินโดยคาดการณ์ว่า บริษัท จะเห็นการลดลงของมูลค่า ในการซื้อขายไบนารีตัวเลือกคุณกำลังเดิมพันว่าราคาของสินทรัพย์เฉพาะอาจเพิ่มขึ้นหรือลดลงในช่วงระยะเวลาที่กำหนด คุณมีความรู้ความสามารถในการเสี่ยงภัยและกลับขึ้นหน้าก่อนที่การค้าจะเกิดขึ้น การซื้อขายไบนารีถือเป็นวิธีที่ยอดเยี่ยมในการเข้าสู่ตลาดโดยไม่ต้องใช้เงินทุนหรือเงินทุนสำรองอย่างมาก ใช้ประโยชน์จากข้อมูลที่นำเสนอใน 7binaryoptions เพื่อทำความเข้าใจเกี่ยวกับตัวเลือกไบนารีและการซื้อขายแลกเปลี่ยนเงินตราต่างประเทศเพื่อสร้างรายได้ออนไลน์ ธนาคารกลางสหรัฐ (โอไฮโอ) คาดการณ์ว่าอัตราดอกเบี้ยของ 039liftoff039 ในระยะยาวอาจจะได้รับในปีนี้เนื่องจากเป็นผู้กำหนดนโยบายจากประธานเจเน็ตเยลเลนในวันศุกร์ที่ผ่านมา ผู้นำทั่วประเทศสหรัฐอเมริกาส่งสัญญาณว่ายุคของเงินที่ง่ายกำลังใกล้เข้ามา จอห์นสันแอมป์จอห์นสัน (Johnson & Johnson Johnson) กล่าวเมื่อวันศุกร์ที่ว่าคณะลูกขุนศาลรัฐในรัฐมิสซูรี่ได้ยื่นคำฟ้องในการพิจารณาคดีครั้งล่าสุดที่เกิดขึ้นจากการฟ้องร้องคดีต่างๆหลายพันรายการที่อ้างว่าผลิตภัณฑ์จากแป้งทาตัวของ บริษัท สามารถเพิ่มความเสี่ยงต่อการเกิดโรคมะเร็งรังไข่ (รอยเตอร์ส) - ท่อส่งน้ำมัน Keystone XL ไม่จำเป็นต้องทำจากเหล็กกล้าของสหรัฐฯแม้ว่าจะมีคำสั่งจากประธานโดนัลด์ทรัมพ์เมื่อวันพุธหลังจากที่เขาเข้ารับตำแหน่งโดยใช้เหล็กกล้าภายในประเทศในท่อใหม่ ผู้บริหารสูงสุดของ Deutsche Boerse Carsten Kengeter กล่าวว่ากำลังเตรียมการควบรวมกิจการกับตลาดหลักทรัพย์ลอนดอน แม้ว่า LSE0 ปฏิเสธที่จะขายแพลตฟอร์มการซื้อขาย MTS ของอิตาลี สำนักข่าวรอยเตอร์รายงานว่าสำนักข่าวอินโฟเควสท์ (IQ) - อังคารที่ 24 กุมภาพันธ์ 2553 11:31:31 น. ดัชนี SampP 500 และ Nasdaq ปิดตลาดร่วงลงเป็นสัปดาห์ที่ 6 ติดต่อกันหลังจากที่เจเน็ตเยลเซ็นรายงานว่าเฟดจะปรับขึ้นอัตราดอกเบี้ยในเดือนนี้หากการจ้างงานและข้อมูลเศรษฐกิจอื่น ๆ พุ่งขึ้น UBER Technologies Inc UBER. UL ได้ใช้มานานหลายปีในการใช้เครื่องมือลับในการหลอกลวงเจ้าหน้าที่ในตลาดที่บริการของ บริษัท ต้องเผชิญกับความต้านทานโดยการบังคับใช้กฎหมายหรือถูกห้ามนิวยอร์กไทม์สรายงานว่าอ้างแหล่งข่าว ศูนย์การค้า Neiman Marcus ในประเทศสหรัฐอเมริกาได้ว่าจ้างธนาคารเพื่อการลงทุน Lazard Ltd เข้ามาสำรวจแนวทางในการเสริมสร้างความสมดุลของงบดุลในขณะที่ บริษัท พยายามลดหนี้จากหนี้จำนวน 4.9 พันล้านคนและคนที่คุ้นเคยกับเรื่องนี้กล่าวเมื่อวันศุกร์ที่ผ่านมา ปารีส - (บิสิเนสการ์ด) - PSA Group ของ France0 เปิดเผยข้อตกลงกับเจเนอรัลมอเตอร์สในการซื้อหน่วยผลิต Opel ของสหรัฐที่สูญเสียรายได้จากการผลิตของสหรัฐซึ่งเป็นแหล่งข่าวสองแห่งที่มีความรู้เรื่อง Reuters บริษัท NBCUniversal ของ Comcast Corp ได้ลงทุน 500 ล้านดอลลาร์ใน Snapchat เจ้าของ Snap Inc. ตามบันทึกในวันศุกร์ที่ผ่านมาซึ่งเป็นกลยุทธ์ล่าสุดที่มุ่งผลักดันการเจริญเติบโตแบบดิจิตอลขณะที่ผู้ชมเข้าชมเนื้อหาออนไลน์ที่ชื่นชอบมากขึ้น (รอยเตอร์ส) - หุ้นของ Caterpillar Inc0 พุ่งขึ้นเมื่อวันศุกร์ที่ผ่านมาหลังจากที่เจ้าหน้าที่บังคับใช้กฎหมายของสหรัฐฯบุกเข้าไปในโรงงานของรัฐอิลลินอยส์ในรัฐอิลลินอยส์สามแห่งเนื่องจากการบริหารงานของ Trump ได้ให้การตรวจสอบข้อเท็จจริงอย่างเข้มงวดในการนำเข้าและส่งออกของ บริษัท ข้ามชาติ แนะนำเกี่ยวกับเรา 038 Disclaimer Disclaimer: 7 Binary Options จะไม่รับผิดชอบต่อความสูญเสียหรือความเสียหายที่เกิดขึ้นจากการพึ่งพาข้อมูลที่มีอยู่ในเว็บไซต์นี้ ข้อมูลที่มีอยู่ในเว็บไซต์นี้ไม่จำเป็นต้องเป็นแบบเรียลไทม์และไม่ถูกต้องและการวิเคราะห์เป็นความคิดเห็นของผู้เขียน 7binaryoptions เป็นเพียงข้อมูลการเสนอเว็บไซต์เท่านั้นไม่ใช่นายหน้าหรือที่ปรึกษาการลงทุนที่ได้รับการควบคุมและไม่มีข้อมูลใดที่มีจุดมุ่งหมายเพื่อรับประกันผลในอนาคต การซื้อขายตัวเลือกแบบไบนารีที่มีความเสี่ยงสูงและไม่เหมาะสำหรับนักลงทุนทุกราย เนื่องจากการสูญเสียของผลิตภัณฑ์ที่ใช้ประโยชน์จากผลิตภัณฑ์สามารถเกินเงินฝากเริ่มแรกและเงินทุนมีความเสี่ยง ก่อนที่จะตัดสินใจเลือกตัวเลือกไบนารีหรือตราสารการเงินอื่น ๆ คุณควรพิจารณาวัตถุประสงค์การลงทุนระดับประสบการณ์และความกระหายที่มีความเสี่ยง ตามข้อกำหนดของ FTC 7BinaryOptions มีความสัมพันธ์ทางการเงินกับผลิตภัณฑ์และบริการบางอย่างที่กล่าวถึงในเว็บไซต์นี้และ 7BinaryOptions อาจได้รับการชดเชยหากผู้บริโภคเลือกที่จะคลิกลิงก์เหล่านี้ในเนื้อหาของเราและลงชื่อสมัครใช้ในที่สุด การใช้เว็บไซต์นี้ถือว่าคุณยอมรับข้อ จำกัด และข้อยกเว้นที่ระบุในข้อจำกัดความรับผิดชอบนี้และหน้าปฏิเสธความรับผิดชอบแยกต่างหาก หากคุณไม่เห็นด้วยกับพวกเขาคุณจะต้องไม่ใช้เว็บไซต์นี้ NewsletterCGI - จัดการคำขออินเทอร์เฟซเกตเวย์ทั่วไปและการตอบกลับคำอธิบาย CGI. pm เป็นโซลูชันที่มีเสถียรภาพสมบูรณ์และเป็นผู้ใหญ่สำหรับการประมวลผลและจัดเตรียมคำขอ HTTP และการตอบสนอง คุณสมบัติที่สำคัญ ได้แก่ การส่งแบบฟอร์มการประมวลผลการอัปโหลดไฟล์การอ่านและการเขียนคุกกี้การสร้างสายอักขระและการจัดการและการประมวลผลและเตรียมส่วนหัว HTTP บางสาธารณูปโภคการสร้าง HTML รวมอยู่ด้วย CGI. pm ทำงานได้ดีในสภาพแวดล้อม CGI. pm ของวานิลลาและยังมาพร้อมกับการสนับสนุน modperl และ modperl2 และ FastCGI ในตัว มีประโยชน์ในการพัฒนาและการกลั่นกรองมานานกว่า 10 ปีด้วยข้อมูลจากผู้ร่วมให้ข้อมูลหลายสิบคนและมีการใช้งานบนเว็บไซต์นับพัน ๆ แห่ง CGI. pm ได้รวมอยู่ใน Perl distribution ตั้งแต่ Perl 5.4 และกลายเป็นมาตรฐาน de facto ลักษณะการเขียนโปรแกรมมีสองรูปแบบของการเขียนโปรแกรมด้วย CGI. pm สไตล์เชิงวัตถุและสไตล์ที่เน้นการทำงาน ในสไตล์เชิงวัตถุคุณจะสร้างอ็อบเจ็กต์ CGI อย่างน้อยหนึ่งรายการและใช้วิธีการวัตถุเพื่อสร้างองค์ประกอบต่างๆของเพจ แต่ละออบเจ็กต์ CGI จะเริ่มต้นด้วยรายการพารามิเตอร์ที่ตั้งชื่อซึ่งส่งผ่านไปยังสคริปต์ CGI ของคุณโดยเซิร์ฟเวอร์ คุณสามารถแก้ไขวัตถุเก็บไว้ในไฟล์หรือฐานข้อมูลและสร้างใหม่ได้ เนื่องจากแต่ละอ็อบเจ็กต์สอดคล้องกับสถานะของสคริปต์ CGI และเนื่องจากแต่ละรายการพารามิเตอร์อ็อบเจ็กต์เป็นอิสระจากรายการอื่น ๆ ซึ่งจะช่วยให้คุณสามารถบันทึกสถานะของสคริปต์และเรียกคืนได้ในภายหลัง ตัวอย่างเช่นการใช้สไตล์เชิงวัตถุนี่คือวิธีที่คุณสร้างหน้า Hello World HTML แบบง่ายๆ: ในรูปแบบที่มุ่งเน้นฟังก์ชันมีออบเจ็กต์ CGI เริ่มต้นที่คุณไม่ค่อยจัดการด้วย คุณเพียงแค่เรียกใช้ฟังก์ชันเพื่อดึงข้อมูลพารามิเตอร์ CGI สร้างแท็ก HTML จัดการคุกกี้และอื่น ๆ ซึ่งจะทำให้คุณมีอินเตอร์เฟซการเขียนโปรแกรมที่สะอาดขึ้น แต่ จำกัด ให้คุณใช้วัตถุ CGI เพียงตัวเดียวในแต่ละครั้ง ตัวอย่างต่อไปนี้จะพิมพ์หน้าเดียวกัน แต่ใช้อินเทอร์เฟซที่มุ่งเน้นฟังก์ชัน ข้อแตกต่างหลัก ๆ คือตอนนี้เราจำเป็นต้องนำเข้าชุดของฟังก์ชันเข้าไปในพื้นที่ชื่อของเรา (โดยปกติคือฟังก์ชันมาตรฐาน) และเราไม่จำเป็นต้องสร้างวัตถุ CGI ตัวอย่างในเอกสารนี้ส่วนใหญ่ใช้รูปแบบเชิงวัตถุ ดูวิธีการใช้ฟังก์ชันการทำงานสำหรับข้อมูลที่สำคัญเกี่ยวกับการเขียนโปรแกรมเชิงฟังก์ชันใน CGI. pm การเรียกใช้ CGI. PM ROUTINES การปฏิบัติงาน CGI. pm มักใช้อาร์กิวเมนต์หลาย ๆ ข้อซึ่งบางครั้งอาจมีถึง 20 ตัวเลือกเพื่อให้ส่วนติดต่อนี้ง่ายขึ้น สไตล์ที่มีลักษณะดังนี้: ชื่ออาร์กิวเมนต์แต่ละตัวจะถูกนำหน้าด้วยเครื่องหมายขีดกลาง ทั้งคำสั่งและเรื่องไม่สำคัญในรายการอาร์กิวเมนต์ type, - Type และ - TYPE เป็นที่ยอมรับทั้งหมด ในความเป็นจริงเฉพาะอาร์กิวเมนต์แรกต้องเริ่มต้นด้วยเครื่องหมายขีดคั่น ถ้าเครื่องหมายขีดคั่นอยู่ในอาร์กิวเมนต์แรก CGI. pm จะถือว่าเป็นเครื่องหมายขีดกลางสำหรับอักขระที่ต่อเนื่อง หลายกิจวัตรเรียกทั่วไปว่ามีเพียงหนึ่งอาร์กิวเมนต์ ในกรณีของการปฏิบัติเหล่านี้คุณสามารถระบุอาร์กิวเมนต์เดี่ยวได้โดยไม่มีชื่ออาร์กิวเมนต์ ส่วนหัว () เกิดขึ้นเป็นหนึ่งในขั้นตอนเหล่านี้ ในกรณีนี้อาร์กิวเมนต์เดี่ยวคือประเภทเอกสาร ขั้นตอนอื่น ๆ ดังกล่าวได้รับการระบุไว้ด้านล่าง บางครั้งการตั้งชื่ออาร์กิวเมนต์คาดว่าจะเป็นสเกลาร์บางครั้งการอ้างอิงถึงอาเรย์และบางครั้งก็เป็นการอ้างอิงถึงแฮช บ่อยครั้งที่คุณสามารถส่งผ่านอาร์กิวเมนต์ชนิดใดก็ได้และขั้นตอนจะทำสิ่งที่เหมาะสมที่สุด เช่น param () ถูกใช้เพื่อตั้งค่าพารามิเตอร์ CGI ให้เป็นค่าเดียวหรือหลายค่า ทั้งสองกรณีมีดังต่อไปนี้: มีการใช้งาน CGI. pm เป็นจำนวนมากโดยเฉพาะในโมดูล แต่จะสร้างขึ้นโดยอัตโนมัติตามความจำเป็น นี่เป็นทางลัด HTML ซึ่งเป็นขั้นตอนที่สร้างแท็ก HTML สำหรับใช้ในหน้าเว็บที่สร้างขึ้นแบบไดนามิก แท็ก HTML มีแอตทริบิวต์ทั้งคู่ (คู่ attributevalue ภายในแท็กตัวเอง) และเนื้อหา (ส่วนระหว่างการเปิดและปิดคู่) เพื่อแยกความแตกต่างระหว่างแอตทริบิวต์และเนื้อหา CGI. pm ใช้การประชุมผ่าน HTML attributes เป็นข้อมูลอ้างอิงแบบแฮช อาร์กิวเมนต์แรกและเนื้อหาถ้ามีเป็นอาร์กิวเมนต์ที่ตามมา ทำงานได้เช่นนี้: แท็ก HTML จะได้รับการอธิบายในรายละเอียดเพิ่มเติมในภายหลัง ผู้ที่มาใหม่หลายคนใน CGI. pm รู้สึกงงงวยความแตกต่างระหว่างอนุสัญญาการโทรสำหรับทางลัด HTML ซึ่งต้องใช้เครื่องหมายวงเล็บปีกการอบ ๆ แอตทริบิวต์แท็ก HTML และอนุสัญญาการเรียกสำหรับขั้นตอนอื่น ๆ ซึ่งจะช่วยในการสร้างแอตทริบิวต์โดยไม่ใช้วงเล็บปีกกา อย่าสับสน เพื่อความสะดวกในวงเล็บปีกกาเป็นตัวเลือกในทุกทางลัด HTML หากต้องการคุณสามารถใช้วงเล็บปีกกาเมื่อโทรไปยังรูทีนใด ๆ ที่ใช้ชื่ออาร์กิวเมนต์ ตัวอย่างเช่นถ้าคุณใช้สวิตช์ - w คุณจะได้รับคำเตือนว่าชื่ออาร์กิวเมนต์ CGI. pm บางส่วนขัดแย้งกับฟังก์ชัน Perl ในตัว อาร์กิวเมนต์ค่านิยมส่วนใหญ่ที่ใช้ในการสร้างเมนูที่มีหลายค่ารวมถึงกลุ่มปุ่มวิทยุและสิ่งที่คล้ายกัน เพื่อให้ได้คำเตือนนี้คุณมีทางเลือกหลายอย่าง: ใช้ชื่ออื่นสำหรับอาร์กิวเมนต์ถ้ามีอยู่ ตัวอย่างเช่น --value เป็นนามแฝงสำหรับ - values เปลี่ยนการใช้อักษรตัวพิมพ์ใหญ่เช่น ค่าต่างๆใส่เครื่องหมายคำพูดรอบ ๆ ชื่ออาร์กิวเมนต์เช่น ค่านิยมหลายครั้งจะทำสิ่งที่เป็นประโยชน์กับอาร์กิวเมนต์ที่มีชื่อซึ่งไม่รู้จัก ตัวอย่างเช่นคุณสามารถสร้างฟิลด์ส่วนหัว HTTP ที่ไม่เป็นมาตรฐานได้โดยระบุชื่อเหล่านี้เป็นอาร์กิวเมนต์ที่ระบุ: ซึ่งจะสร้างส่วนหัว HTTP ที่ไม่เป็นไปตามมาตรฐานต่อไปนี้: สังเกตวิธีที่เครื่องหมายทับจะแปลโดยอัตโนมัติเป็นยัติภังค์ ขั้นตอนการสร้าง HTML จะใช้การแปลประเภทต่างๆ คุณลักษณะนี้ช่วยให้คุณสามารถปฏิบัติตามมาตรฐาน HTTP และ HTML ที่เปลี่ยนแปลงอย่างรวดเร็ว สร้างแบบสอบถามใหม่ (OBJECT-ORIENTED STYLE): เป็นการแยกวิเคราะห์อินพุท (จากวิธี POST, GET และ DELETE) และเก็บข้อมูลลงในวัตถุ perl5 ที่เรียกว่า query การจัดการไฟล์จากไฟล์อัพโหลดจะมีการตั้งค่าตำแหน่งของพวกเขาไว้ที่ตำแหน่งเริ่มต้นของไฟล์ การสร้างวัตถุข้อมูลใหม่จากไฟล์ INPUT ถ้าคุณให้หมายเลขอ้างอิงไฟล์เป็นเมธอด new () จะอ่านพารามิเตอร์จากไฟล์ (หรือ STDIN หรืออะไรก็ตาม) ไฟล์สามารถอยู่ในรูปแบบใด ๆ ที่อธิบายด้านล่างนี้ภายใต้การดีบัก (เช่นคู่ TAGVALUE ที่คั่นด้วย newline จะทำงาน) ไฟล์ประเภทนี้ถูกสร้างขึ้นโดยวิธี save () (ดูด้านล่าง) สามารถบันทึกและเรียกคืนข้อมูลหลายรายการได้ ผู้เพียรของ Perl ยินดีที่จะทราบว่าไวยากรณ์นี้ยอมรับการอ้างอิงไปยังไฟล์จัดการหรือแม้แต่การอ้างถึงไฟล์รูปภาพซึ่งเป็นวิธีการอย่างเป็นทางการในการส่งไฟล์ไปยังไฟล์: คุณสามารถเริ่มต้นวัตถุ CGI ด้วย FileHandle หรือ IO :: File ได้ ถ้าคุณใช้อินเทอร์เฟซที่มุ่งเน้นการทำงานและต้องการเริ่มต้นสถานะ CGI จากที่จับไฟล์วิธีการทำเช่นนี้ก็คือการเรียกคืนค่าพารามิเตอร์ () นี้จะ (อีกครั้ง) เริ่มต้นวัตถุ CGI เริ่มต้นจากที่ระบุไว้จัดการไฟล์ นอกจากนี้คุณสามารถเริ่มต้นวัตถุแบบสอบถามจากการอ้างอิงแบบแฮชด้วยหรือจากสตริงข้อความค้นหาที่ถูกจัดรูปแบบถูกต้องหรือจากวัตถุ CGI ที่มีอยู่ก่อนหน้านี้ (ปัจจุบันนี้จะคัดลอกรายการพารามิเตอร์ แต่ไม่มีฟิลด์ข้อมูลเฉพาะอื่น ๆ เช่น เป็นแบบอัตโนมัติ (autoescaping)): เมื่อต้องการสร้าง Query ว่างให้เริ่มต้นจากสตริงที่ว่างเปล่าหรือ hash: การเรียกค้นรายการคำหลักจาก Query: หากสคริปต์ถูกเรียกใช้เป็นผลจากการค้นหา ltisINDEXgt คำหลักที่แยกวิเคราะห์สามารถเป็นอาร์เรย์ได้ ใช้คำหลัก () method การเรียกชื่อของพารามิเตอร์ทั้งหมดที่ตรงกับรูปของคุณ: ถ้าสคริปต์ถูกเรียกใช้กับรายการพารามิเตอร์ (เช่น name1value1ampname2value2ampname3value3) เมธอด param () จะคืนค่าชื่อพารามิเตอร์เป็นรายการ หากสคริปต์ถูกเรียกใช้เป็นสคริปต์ ltisINDEXgt และมีสตริงที่ไม่มีเครื่องหมายอัชเชอร์ (เช่น value1value2value3) จะมีพารามิเตอร์เดียวที่มีชื่อว่าคำหลักที่มีคำหลักที่ถูก จำกัด ไว้ หมายเหตุ: ตั้งแต่เวอร์ชัน 1.5 อาร์เรย์ของชื่อพารามิเตอร์ที่ส่งคืนจะอยู่ในลำดับเดียวกับที่ได้รับจากเบราว์เซอร์ โดยปกติคำสั่งนี้จะเหมือนกับคำสั่งที่มีการกำหนดค่าพารามิเตอร์ไว้ในฟอร์ม (แต่นี่ไม่ใช่ส่วนหนึ่งของข้อมูลจำเพาะและไม่รับประกัน) การหาค่าหรือค่าของพารามิเตอร์ชื่อเดียว: ส่งพารามิเตอร์ param () เป็นอาร์กิวเมนต์เดี่ยวเพื่อดึงค่าของพารามิเตอร์ที่ระบุ หากพารามิเตอร์มีหลายค่า (เช่นจากการเลือกหลายรายการในรายการแบบเลื่อน) คุณสามารถขอรับอาร์เรย์ได้ มิฉะนั้นวิธีจะคืนค่าเดียว หากไม่มีค่าในสตริงข้อความค้นหาเช่นเดียวกับในแบบสอบถาม name1ampname2 รหัสจะถูกส่งกลับเป็นสตริงว่าง ถ้าพารามิเตอร์ไม่อยู่เลย param () จะกลับ undef ในบริบท scalar และรายการที่ว่างเปล่าในบริบทของรายการ การตั้งค่า (S) ของพารามิเตอร์ที่ระบุ: ตั้งค่าสำหรับพารามิเตอร์ที่มีชื่อ foo เป็นอาร์เรย์ของค่า นี่เป็นวิธีหนึ่งในการเปลี่ยนค่าของฟิลด์หลังการเรียกใช้สคริปต์ครั้งเดียว (อีกวิธีหนึ่งคือการใช้พารามิเตอร์ - override ที่ยอมรับโดยเมธอดทั้งหมดที่สร้างอิลิเมนต์ของฟอร์ม) param () ยังรู้จักรูปแบบพารามิเตอร์ที่มีชื่อเรียกว่าอธิบายในรายละเอียดเพิ่มเติมในภายหลัง: การเพิ่มมูลค่าเพิ่มเติมเป็นพารามิเตอร์ที่ระบุ: เพิ่มมูลค่าหรือรายการ ของค่าไปยังพารามิเตอร์ที่ระบุ ค่าจะถูกผนวกเข้ากับส่วนท้ายของพารามิเตอร์หากมีอยู่แล้ว มิฉะนั้นพารามิเตอร์จะถูกสร้างขึ้น โปรดทราบว่าเมธอดนี้รู้จักเฉพาะไวยากรณ์เรียกอาร์กิวเมนต์ที่มีชื่อ การนำเข้าพารามิเตอร์ทั้งหมดเข้าสู่ NAMESPACE: ซึ่งจะสร้างชุดของตัวแปรใน R namespace ตัวอย่างเช่น R :: foo, R: foo สำหรับรายการคำหลักตัวแปร R :: keywords จะปรากฏขึ้น ถ้าไม่มี namespace จะได้รับวิธีนี้จะถือว่า Q. คำเตือน: dont นำเข้าอะไรเป็นหลักนี้เป็นความเสี่ยงด้านความปลอดภัยที่สำคัญ หมายเหตุ 1: เปลี่ยนชื่อตัวแปรตามความจำเป็นในชื่อตัวแปร Perl ตามกฎหมาย อักขระที่ไม่ใช่กฎหมายทั้งหมดจะเปลี่ยนเป็นเครื่องหมายขีดล่าง หากต้องการเก็บชื่อเดิมคุณควรใช้วิธี param () แทนที่จะเข้าถึงตัวแปร CGI ตามชื่อ หมายเหตุ 2: ในเวอร์ชันที่เก่ากว่าวิธีนี้เรียกว่า import () ตั้งแต่เวอร์ชัน 2.20 ชื่อนี้ถูกลบออกอย่างสมบูรณ์เพื่อหลีกเลี่ยงความขัดแย้งกับตัวดำเนินการนำเข้าโมดูล Perl ในตัว การลบพารามิเตอร์อย่างสมบูรณ์: การดำเนินการนี้จะล้างรายการพารามิเตอร์ทั้งหมด บางครั้งก็มีประโยชน์สำหรับการรีเซ็ตพารามิเตอร์ที่คุณไม่ต้องการส่งผ่านระหว่างการเรียกอินสแตนซ์ของสคริปต์ ถ้าคุณใช้อินเทอร์เฟซการเรียกฟังก์ชันให้ใช้ Delete () แทนเพื่อหลีกเลี่ยงความขัดแย้งกับตัวดำเนินการลบ Perls ที่มีอยู่ การลบพารามิเตอร์ทั้งหมด: การดำเนินการนี้จะล้างวัตถุ CGI ให้สมบูรณ์ อาจเป็นประโยชน์เพื่อให้แน่ใจว่าค่าดีฟอลต์ทั้งหมดจะถูกนำมาเมื่อคุณสร้างแบบฟอร์มการกรอกข้อมูล ใช้ Deleteall () แทนถ้าคุณใช้อินเตอร์เฟสการเรียกฟังก์ชัน การประมวลผลอาร์กิวเมนต์ที่ไม่ได้รับการเข้ารหัส URL ถ้าข้อมูล POSTed ไม่ใช่แบบ typex-www - form-urlencoded หรือ multipartform ข้อมูลจะไม่มีการประมวลผลข้อมูล POSTed แต่จะส่งกลับตาม - อยู่ในพารามิเตอร์ที่ชื่อ POSTDATA ในการดึงข้อมูลให้ใช้รหัสเช่นนี้: เช่นเดียวกันหากสามารถเรียกข้อมูล PUTed ด้วยรหัสดังนี้: (หากคุณไม่ทราบว่าสิ่งที่หมายความว่าก่อนหน้านี้ไม่ต้องห่วงเรื่องนี้มีผลกับผู้ใช้ CGI เพื่อประมวลผล XML และผู้เชี่ยวชาญเฉพาะรายอื่นเท่านั้น งาน) การเข้าถึงรายชื่อพารามิเตอร์โดยตรง: หากต้องการเข้าถึงรายการพารามิเตอร์ตามวิธีที่ระบุไว้ในส่วนก่อนหน้านี้คุณสามารถขอรับข้อมูลอ้างอิงโดยตรงได้โดยการเรียกใช้เมธอด paramfetch () ด้วย ชื่อของพารามิเตอร์ การดำเนินการนี้จะส่งกลับการอ้างอิงอาร์เรย์ไปยังพารามิเตอร์ที่มีชื่อซึ่งคุณสามารถจัดการได้ในแบบที่คุณต้องการ นอกจากนี้คุณยังสามารถใช้อาร์กิวเมนต์ชื่อได้โดยใช้อาร์กิวเมนต์ชื่อ การเรียกรายชื่อพารามิเตอร์เป็นแฮช: หลายคนต้องการเรียกรายการพารามิเตอร์ทั้งหมดเป็นแฮชซึ่งคีย์เป็นชื่อของพารามิเตอร์ CGI และค่าเป็นค่าพารามิเตอร์ วิธี Vars () ทำสิ่งนี้ เรียกว่าในบริบท scalar จะแสดงรายการพารามิเตอร์เป็นข้อมูลอ้างอิงแบบแฮะ การเปลี่ยนคีย์จะเปลี่ยนค่าของพารามิเตอร์ในรายการพารามิเตอร์ CGI อ้างอิง เรียกว่าในบริบทของรายการจะแสดงรายการพารามิเตอร์เป็นแฮชแบบธรรมดา ซึ่งจะช่วยให้คุณสามารถอ่านเนื้อหาของรายการพารามิเตอร์ได้ แต่จะไม่สามารถแก้ไขได้ เมื่อใช้สิ่งนี้คุณต้องระมัดระวังเป็นพารามิเตอร์ CGI แบบหลายค่า เนื่องจากแฮชไม่สามารถแยกความแตกต่างระหว่างบริบท scalar และรายการพารามิเตอร์ที่มีหลายค่าจะถูกส่งกลับเป็นสตริงที่บรรจุโดยคั่นด้วยอักขระ 0 (null) คุณต้องแยกสตริงที่บรรจุนี้เพื่อให้ได้ค่าแต่ละอย่าง นี่เป็นการประชุมที่ Steve Brenner เคยใช้มาก่อนในโมดูล cgi-lib. pl ของเขาสำหรับ Perl เวอร์ชัน 4 ถ้าคุณต้องการใช้ Vars () เป็นฟังก์ชันให้นำเข้า: cgi-lib set of functions calls (ดูส่วนนี้) ความเข้ากันได้ของ CGI-LIB) การบันทึกสถานะของไฟล์เป็นไฟล์: จะเป็นการเขียนสถานะปัจจุบันของฟอร์มไปยังไฟล์ที่มีให้ คุณสามารถอ่านมันกลับมาได้โดยการให้ filehandle ไปเป็นเมธอด new () โปรดทราบว่า filehandle สามารถเป็นไฟล์ท่อหรือสิ่งใดก็ได้รูปแบบของไฟล์ที่บันทึกไว้คือชื่อและค่าเป็น URL ที่หลบหนีได้ พารามิเตอร์ CGI ที่มีหลายค่าจะแสดงเป็นชื่อซ้ำ บันทึกเซสชันถูกคั่นด้วยสัญลักษณ์เดียว คุณสามารถเขียนเร็กคอร์ดหลายรายการและอ่านกลับมาได้หลายครั้ง คุณสามารถทำสิ่งนี้ได้ในหลาย ๆ เซสชันโดยการเปิดไฟล์ในโหมดต่อท้ายช่วยให้คุณสามารถสร้างหนังสือสำหรับผู้เข้าชมแบบดั้งเดิมหรือเพื่อเก็บประวัติการค้นหาผู้ใช้ นี่เป็นตัวอย่างสั้น ๆ เกี่ยวกับการสร้างบันทึกเซสชันหลายรูปแบบ: รูปแบบไฟล์ที่ใช้สำหรับ saverestore จะเหมือนกับข้อมูลที่ใช้โดยศูนย์ข้อมูล Genome Genhe Centers ในรูปแบบการแลกเปลี่ยนข้อมูล Boulderio และสามารถจัดการและใช้ข้อมูลได้โดยใช้โปรแกรมอรรถประโยชน์ Boulderio ดูรายละเอียดเพิ่มเติมได้ที่ ถ้าคุณต้องการใช้วิธีนี้จากอินเทอร์เฟซที่มุ่งเน้นฟังก์ชัน (ไม่ใช่ OO) ชื่อที่เอ็กซ์พอร์ตสำหรับวิธีนี้คือ ข้อผิดพลาดในการกู้คืน CGI ข้อผิดพลาดอาจเกิดขึ้นขณะกำลังประมวลผลข้อมูลของผู้ใช้โดยเฉพาะเมื่อประมวลผลไฟล์ที่อัปโหลด เมื่อเกิดข้อผิดพลาดเหล่านี้ CGI จะหยุดประมวลผลและส่งคืนค่าพารามิเตอร์ว่างเปล่า คุณสามารถทดสอบการดำรงอยู่และลักษณะของข้อผิดพลาดโดยใช้ฟังก์ชัน cgierror () ข้อความแสดงข้อผิดพลาดถูกจัดรูปแบบเป็นรหัสสถานะ HTTP คุณสามารถรวมข้อความแสดงข้อผิดพลาดลงในหน้า HTML หรือใช้เป็นค่าสถานะ HTTP: เมื่อใช้อินเทอร์เฟซที่มุ่งเน้นฟังก์ชัน (ดูหัวข้อถัดไป) ข้อผิดพลาดอาจเกิดขึ้นในครั้งแรกที่คุณเรียกใช้ param () เท่านั้น เตรียมพร้อมสำหรับการใช้อินเตอร์เฟสที่ใช้ฟังก์ชันนี้เพื่อใช้อินเทอร์เฟซที่มุ่งเน้นการทำงานคุณต้องระบุว่าควรใช้ CGI. pm หรือชุดคำสั่งที่จะนำเข้าสู่ namespace ของสคริปต์ของคุณ มีค่าใช้จ่ายเล็ก ๆ ที่เกี่ยวข้องกับการนำเข้านี้ แต่ก็ไม่มากนัก วิธีการที่ระบุจะถูกนำเข้าไปยังแพคเกจปัจจุบันที่คุณสามารถเรียกใช้ได้โดยตรงโดยไม่ต้องสร้างวัตถุ CGI ก่อน ตัวอย่างนี้แสดงวิธีการนำเข้าวิธี param () และส่วนหัว () จากนั้นใช้โดยตรง: บ่อยครั้งคุณจะนำเข้าชุดฟังก์ชันทั่วไปโดยอ้างถึงกลุ่มตามชื่อ ชุดฟังก์ชันทั้งหมดจะมีอักขระดังนี้: html3 (สำหรับแท็กที่กำหนดไว้ในมาตรฐาน HTML 3) นี่คือรายการของชุดฟังก์ชันที่คุณสามารถนำเข้า: นำเข้าวิธีการจัดการ CGI ทั้งหมดเช่น param () pathinfo () และสิ่งที่คล้ายกัน นำเข้าวิธีการสร้างฟอร์มการกรอกข้อมูลทั้งหมดเช่น textfield () นำเข้าวิธีการทั้งหมดที่สร้างองค์ประกอบมาตรฐาน HTML 2.0 นำเข้าวิธีการทั้งหมดที่สร้างองค์ประกอบ HTML 3.0 (เช่น lttablegt, ltsupergt และ ltsubgt) นำเข้าวิธีการทั้งหมดที่สร้างองค์ประกอบ HTML 4 (เช่น ltabbrevgt, ltacronymgt และ lttheadgt) นำเข้าแท็ก ltblinkgt, ltfontsizegt และ ltcentergt นำเข้าทางลัด HTML ที่สร้างทั้งหมด (เช่น html2, html3, html4 และ netscape) นำเข้าคุณลักษณะมาตรฐาน HTML2, HTML3, HTML4, ฟอร์มและ cgi นำเข้าวิธีการทั้งหมดที่มีอยู่ สำหรับรายการแบบเต็มให้ดูที่โค้ด CGI. pm ซึ่งกำหนดตัวแปร EXPORTTAGS ไว้ ถ้าคุณนำเข้าชื่อฟังก์ชันที่ไม่ใช่ส่วนหนึ่งของ CGI. pm โมดูลจะถือว่าเป็นแท็ก HTML ใหม่และสร้างกระบวนการย่อยที่เหมาะสม จากนั้นคุณสามารถใช้งานได้เหมือนกับแท็ก HTML อื่น ๆ นี่คือการจัดเตรียมมาตรฐาน HTML ที่พัฒนาขึ้นอย่างรวดเร็ว ตัวอย่างเช่นสมมติว่า Microsoft ออกมาพร้อมกับแท็กใหม่ที่เรียกว่า ltgradientgt (ซึ่งทำให้เดสก์ท็อปของผู้ใช้ถูกน้ำท่วมด้วยการไล่ระดับสีแบบหมุนจนกว่าเครื่องของเขาจะเริ่มต้นใหม่) คุณไม่ต้องรอเวอร์ชันใหม่ของ CGI. pm เพื่อเริ่มใช้งานได้ทันที: โปรดทราบว่าในความสนใจของความเร็วในการประมวลผล CGI. pm ไม่ใช้ไวยากรณ์ของ Exporter มาตรฐานในการระบุสัญลักษณ์โหลด ซึ่งอาจมีการเปลี่ยนแปลงในอนาคต หากคุณนำเข้า CGI ที่รักษาโดยรัฐหรือวิธีการสร้างแบบฟอร์มวัตถุ CGI เริ่มต้นจะถูกสร้างขึ้นและเริ่มต้นโดยอัตโนมัติในครั้งแรกที่คุณใช้วิธีใดวิธีหนึ่งที่ต้องมีอยู่ ซึ่งรวมถึง param () ช่องข้อความ() . submit () และสิ่งที่คล้ายกัน (ถ้าคุณต้องการเข้าถึงวัตถุ CGI โดยตรงคุณสามารถค้นหาได้ในตัวแปร CGI :: Q ทั่วโลก) เมื่อนำเข้าวิธีการ CGI. pm คุณสามารถสร้างสคริปต์ที่ดูหรูหราได้: นอกจากชุดฟังก์ชันแล้วยังมี pragmas จำนวนมากที่คุณสามารถนำเข้าได้ Pragmas ซึ่งนำหน้าด้วยเครื่องหมายยัติภังค์เสมอเปลี่ยนวิธีที่ CGI. pm ทำงานในรูปแบบต่างๆ คุณสามารถนำเข้า Pragmas, ชุดฟังก์ชั่นและแต่ละฟังก์ชันได้ในบรรทัดการใช้งานเดียวกัน () ตัวอย่างเช่นคำสั่งใช้ต่อไปนี้จะนำเข้าชุดฟังก์ชันมาตรฐานและเปิดใช้งานโหมดดีบัก (pragma - debug): รายการ pragmas ปัจจุบันมีดังต่อไปนี้: เมื่อคุณใช้ CGI - any แล้ววิธีการใด ๆ ที่วัตถุแบบสอบถามไม่รู้จักจะถูกแปลเป็นแท็ก HTML ใหม่ ซึ่งจะช่วยให้คุณสามารถสนับสนุนส่วนขยาย HTML เฉพาะกิจต่อไปได้ วิธีนี้ช่วยให้คุณสามารถใช้งานแท็กใหม่และไม่ได้รับการสนับสนุนได้: เนื่องจากการใช้ ltcitegtanyltcitegt ทำให้ชื่อเมธอดที่ถูกเมาเหล้าใด ๆ ถูกตีความว่าเป็นแท็ก HTML ใช้อย่างระมัดระวังหรือไม่ใช้เลย ซึ่งทำให้วิธีการที่โหลดอัตโนมัติที่ระบุจะถูกรวบรวมขึ้นด้านหน้าแทนที่จะเลื่อนไปในภายหลัง นี่เป็นประโยชน์สำหรับสคริปต์ที่รันเป็นระยะเวลาที่ยาวนานภายใต้ FastCGI หรือ modperl และสำหรับผู้ที่กำหนดให้ถูกกระทืบโดย Malcolm Beatties Perl compiler ใช้ร่วมกับวิธีการหรือวิธีการที่ครอบครัวคุณวางแผนที่จะใช้ โปรดทราบว่าการใช้ pragma - compile ในลักษณะนี้มักจะมีผลของการนำเข้าฟังก์ชันที่รวบรวมไว้ใน namespace ปัจจุบัน ถ้าคุณต้องการคอมไพล์โดยไม่ต้องนำเข้าให้ใช้วิธีการคอมไพล์ () แทน: นี่เป็นประโยชน์อย่างยิ่งในสภาพแวดล้อมของ modperl ซึ่งคุณอาจต้องการคอมไพล์ขั้นตอน CGI ทั้งหมดในสคริปต์การเริ่มต้นระบบจากนั้นนำเข้าฟังก์ชันต่างๆทีละไฟล์ในสคริปต์ modperl แต่ละไฟล์ โดยค่าเริ่มต้นโมดูล CGI จะใช้ลักษณะการรักษาสถานะที่เรียกว่าเขตข้อมูลที่เหนียว วิธีการทำงานนี้ก็คือถ้าคุณกำลังสร้างฟอร์มใหม่วิธีการที่สร้างค่าของฟิลด์แบบฟอร์มจะถาม param () เพื่อดูว่าพารามิเตอร์ที่มีชื่อเดียวกันมีอยู่ในสตริงการค้นหาหรือไม่ หากพบพารามิเตอร์ที่มีชื่อเหมือนกันพวกเขาจะใช้พารามิเตอร์นี้เพื่อตั้งค่าเริ่มต้น บางครั้งนี่ไม่ใช่สิ่งที่คุณต้องการ pragma - nosticky ป้องกันพฤติกรรมนี้ นอกจากนี้คุณยังสามารถเลือกลักษณะการทำงานที่เหนียวเหนอะหนะในแต่ละองค์ประกอบที่คุณสร้างได้ เพิ่มแอตทริบิวต์ของดัชนีแท็กโดยอัตโนมัติไปยังแต่ละฟิลด์ของฟอร์ม เมื่อปิดใช้งานตัวเลือกนี้คุณยังคงสามารถเพิ่มดัชนีของแท็บด้วยตนเองโดยการส่งผ่านตัวเลือก - tabindex ไปยังแต่ละวิธีที่สร้างฟิลด์ วิธีนี้จะเก็บ CGI. pm จากรวมพารามิเตอร์ undef ในรายการพารามิเตอร์ โดยค่าเริ่มต้น CGI. pm เวอร์ชัน 2.69 ขึ้นไปจะแสดง XHTML (w3.orgTRxhtml1) - noxhtml pragma ปิดใช้งานคุณลักษณะนี้ ขอขอบคุณ Michalis Kabrianis ltkabrianishellug. grgt สำหรับคุณลักษณะนี้ ถ้าพารามิเตอร์ s - dtd starthtml () ระบุ HTML 2.0, 3.2, 4.0 หรือ 4.01 DTD XHTML จะถูกปิดโดยอัตโนมัติโดยไม่ต้องใช้ pragma นี้ ซึ่งทำให้ CGI. pm ใช้พารามิเตอร์ทั้งหมดเป็นสตริง UTF-8 ใช้สิ่งนี้ด้วยความระมัดระวังเนื่องจากจะรบกวนการประมวลผลการอัปโหลดไบนารี ควรเลือกฟิลด์ที่ต้องการให้ utf-8 สตริงและแปลงโค้ดโดยใช้โค้ดดังนี้: CGI. pm สร้างส่วนหัวที่เหมาะสมสำหรับสคริปต์ NPH (ไม่มีส่วนหัว) คุณอาจต้องทำสิ่งอื่นเช่นกันเพื่อแจ้งเซิร์ฟเวอร์ว่าสคริปต์เป็น NPH ดูบทสนทนาของสคริปต์ NPH ด้านล่าง แยกคู่ namevalue ในสตริงการค้นหาพารามิเตอร์ CGI ด้วยเครื่องหมายอัฒภาคมากกว่าเครื่องหมายอัศเจรีย์ ตัวอย่างเช่น: สตริงแบบสอบถามที่คั่นด้วยเซมิคอนดักเตอร์เป็นที่ยอมรับกันเสมอและจะถูกส่งโดย selfurl () และ Querystring () newstyleurls กลายเป็นค่าเริ่มต้นในเวอร์ชัน 2.64 แยกคู่ namevalue ในสตริงการค้นหาพารามิเตอร์ CGI กับเครื่องหมายอัชเชอร์แทนที่จะใช้เครื่องหมายอัฒภาค นี่ไม่ใช่ค่าดีฟอลต์ การดำเนินการนี้จะแทนที่ตัวโหลดอัตโนมัติเพื่อให้ฟังก์ชันใด ๆ ในโปรแกรมของคุณที่ไม่ได้รับการยอมรับถูกอ้างถึง CGI. pm สำหรับการประเมินผลที่เป็นไปได้ ซึ่งจะช่วยให้คุณสามารถใช้ฟังก์ชัน CGI. pm ทั้งหมดได้โดยไม่ต้องเพิ่มลงในตารางสัญลักษณ์ซึ่งเป็นกังวลสำหรับผู้ใช้ modperl ที่กังวลเกี่ยวกับการใช้หน่วยความจำ คำเตือน: เมื่อ --autoload มีผลคุณไม่สามารถใช้โหมดบทกวี (ฟังก์ชั่นที่ไม่มีวงเล็บ) ใช้ hr () มากกว่า hr หรือเพิ่มสิ่งที่ต้องการใช้หัวข้อย่อย qwhr p ไปที่ด้านบนของสคริปต์ของคุณ ซึ่งจะปิดคุณลักษณะการประมวลผลบรรทัดคำสั่ง ถ้าคุณต้องการเรียกใช้สคริปต์ CGI. pm จากบรรทัดคำสั่งเพื่อสร้าง HTML และคุณไม่ต้องการให้อ่านพารามิเตอร์ CGI จากบรรทัดคำสั่งหรือ STDIN จากนั้นใช้ pragma นี้: เปิดการดีบักแบบเต็ม นอกเหนือจากการอ่านอาร์กิวเมนต์ CGI จากการประมวลผลบรรทัดคำสั่งแล้ว CGI. pm จะหยุดชั่วคราวและพยายามอ่านอาร์กิวเมนต์จาก STDIN ซึ่งจะสร้างข้อความ (โหมดออฟไลน์: ป้อนคู่ namevalue บนอินพุตมาตรฐาน) ดูส่วนการแก้จุดบกพร่องสำหรับรายละเอียดเพิ่มเติม CGI. pm สามารถประมวลผลไฟล์ที่อัปโหลด ปกติมัน spools ไฟล์ที่อัปโหลดไปยังไดเรกทอรีชั่วคราวแล้วลบไฟล์เมื่อทำ อย่างไรก็ตามการดำเนินการดังกล่าวจะทำให้ความเสี่ยงในการดักฟังข้อมูลในส่วนที่อัพโหลดขึ้น ผู้เขียนสคริปต์อีก CGI อาจแอบมองข้อมูลนี้ระหว่างอัปโหลดแม้ว่าจะเป็นข้อมูลที่เป็นความลับก็ตาม ในระบบยูนิกซ์ - privatetempfiles pragma จะทำให้ไฟล์ชั่วคราวถูกยกเลิกการเชื่อมต่อทันทีที่มีการเปิดและก่อนที่ข้อมูลใด ๆ จะถูกเขียนลงไปให้ลด แต่ไม่สามารถลดความเสี่ยงจากการถูกดักฟัง เพื่อให้ชีวิตผู้บุกรุกหนักขึ้นโปรแกรมจะเลือกชื่อ tempfile โดยการคำนวณ checksum 32 บิตของส่วนหัว HTTP ที่เข้ามา เพื่อให้แน่ใจว่าไฟล์สคริปต์ชั่วคราวไม่สามารถอ่านได้โดยสคริปต์ CGI อื่น ๆ ให้ใช้ suEXEC หรือโปรแกรม wrapper CGI เพื่อเรียกใช้สคริปต์ของคุณ แฟ้มชั่วคราวถูกสร้างขึ้นด้วยโหมด 0600 (ทั้งโลกหรือกลุ่มสามารถอ่านได้) ไดเร็กทอรีชั่วคราวถูกเลือกโดยใช้อัลกอริทึมต่อไปนี้: แต่ละตำแหน่งจะถูกตรวจสอบว่าเป็นไดเร็กทอรีและสามารถเขียนได้ ถ้าไม่ใช้อัลกอริธึมพยายามเลือกตัวเลือกถัดไป รูปแบบพิเศษสำหรับการนำเข้า HTML-TAG FUNCTIONS หลายวิธีสร้างแท็ก HTML ดังที่อธิบายไว้ด้านล่างฟังก์ชันแท็กจะสร้างทั้งแท็กเปิดและปิดโดยอัตโนมัติ ตัวอย่างเช่นจะมีบางครั้งที่คุณต้องการสร้างแท็กเริ่มต้นและสิ้นสุดด้วยตัวคุณเอง ในกรณีนี้คุณสามารถใช้แท็กเริ่มต้นของรูปแบบและแท็กสิ้นสุด เช่นเดียวกับ: มีข้อยกเว้นบางประการ (อธิบายด้านล่าง) เริ่มใช้งานฟังก์ชัน tagname และ end tagname ไม่ได้สร้างขึ้นโดยอัตโนมัติเมื่อคุณใช้ CGI อย่างไรก็ตามคุณสามารถระบุแท็กที่คุณต้องการสร้างฟังก์ชันเริ่มต้นด้วยการใส่เครื่องหมายดอกจันไว้ข้างหน้าชื่อของตนหรือหรือขอเปลี่ยนชื่อแท็กเริ่มต้นหรือปลายทางในรายการนำเข้า ในตัวอย่างนี้ฟังก์ชันต่อไปนี้สร้างขึ้นนอกเหนือจากไฟล์มาตรฐาน: 1. starttable () (สร้างแท็ก lttablegt) 2. endtable () (สร้างแท็ก lttablegt) 3. startul () (สร้างแท็ก ltulgt) 4 endul () (สร้างแท็ก ltulgt) การสร้างเอกสารแบบไดนามิกฟังก์ชัน CGI. pms ส่วนใหญ่จะจัดการกับการสร้างเอกสารได้ทันที โดยทั่วไปคุณจะผลิตส่วนหัว HTTP แรกตามด้วยเอกสารเอง CGI. pm มีฟังก์ชันสำหรับสร้างส่วนหัว HTTP ของประเภทต่างๆรวมถึงการสร้าง HTML สำหรับการสร้างภาพ GIF โปรดดูโมดูล GD. pm แต่ละฟังก์ชันเหล่านี้จะสร้างส่วนย่อย HTML หรือ HTTP ซึ่งคุณสามารถพิมพ์ออกมาได้โดยตรงเพื่อให้แสดงในหน้าต่างเบราว์เซอร์ต่อท้ายสตริงหรือบันทึกลงในไฟล์เพื่อใช้ในภายหลัง การสร้างมาตรฐาน HTTP HEADER: โดยปกติสิ่งแรกที่คุณจะต้องทำในสคริปต์ CGI คือพิมพ์ส่วนหัว HTTP ซึ่งจะบอกเบราเซอร์เกี่ยวกับประเภทของเอกสารที่ต้องการและให้ข้อมูลเพิ่มเติมเช่นภาษาวันที่หมดอายุและจะแคชเอกสารหรือไม่ ส่วนหัวยังสามารถจัดการเพื่อวัตถุประสงค์พิเศษเช่นการผลักดันของเซิร์ฟเวอร์และจ่ายต่อการดูหน้าเว็บ ส่วนหัว () จะแสดงส่วนหัวของ Content-type: คุณสามารถระบุประเภท MIME ของคุณเองหากคุณเลือกมิฉะนั้นจะเป็นค่าเริ่มต้นสำหรับ texthtml พารามิเตอร์ที่สองที่เป็นตัวระบุระบุรหัสสถานะและข้อความที่มนุษย์สามารถอ่านได้ ตัวอย่างเช่นคุณสามารถระบุ 204 ไม่มีการตอบสนองเพื่อสร้างสคริปต์ที่บอกให้เบราว์เซอร์ไม่ทำอะไรเลย โปรดสังเกตว่า RFC 2616 คาดว่าเฟสที่มนุษย์สามารถอ่านได้จะมีอยู่รวมทั้งรหัสสถานะตัวเลข ตัวอย่างสุดท้ายแสดงรูปแบบอาร์กิวเมนต์ที่ระบุสำหรับการส่งผ่านอาร์กิวเมนต์ไปยังเมธอด CGI โดยใช้พารามิเตอร์ที่ระบุ พารามิเตอร์ที่ได้รับการยอมรับคือ - type --status - คาดไม่ถึง และ - cookie พารามิเตอร์ที่ตั้งชื่ออื่น ๆ จะถูกตัดจากยัติภังค์เริ่มแรกและกลายเป็นฟิลด์ส่วนหัวซึ่งช่วยให้คุณสามารถระบุส่วนหัว HTTP ที่ต้องการได้ เครื่องหมายขีดล่างภายในจะกลายเป็นเครื่องหมายยัติภังค์: เบราว์เซอร์ส่วนใหญ่จะไม่แคชเอาต์พุตจากสคริปต์ CGI ทุกครั้งที่เบราว์เซอร์โหลดหน้าใหม่สคริปต์จะถูกเรียกใหม่ คุณสามารถเปลี่ยนลักษณะการทำงานนี้ได้โดยใช้พารามิเตอร์ - expires เมื่อคุณระบุช่วงหมดอายุที่แน่นอนหรือญาติกับพารามิเตอร์นี้เบราว์เซอร์และพร็อกซีเซิร์ฟเวอร์บางตัวจะแคชเอาต์พุตจนกว่าจะถึงวันหมดอายุที่ระบุไว้ ฟอร์มต่อไปนี้ใช้ได้สำหรับฟิลด์ - expires: พารามิเตอร์ - cookie สร้างส่วนหัวที่บอกให้เบราว์เซอร์ระบุคุกกี้มายากลในระหว่างการทำธุรกรรมทั้งหมดที่ตามมากับสคริปต์ของคุณ คุกกี้บางตัวมีรูปแบบพิเศษที่มีแอตทริบิวต์ที่น่าสนใจเช่นเวลาหมดอายุ ใช้คุกกี้ () เพื่อสร้างและเรียกคืนคุกกี้เซสชัน พารามิเตอร์ - nph ถ้าตั้งค่าเป็น true จะใช้ส่วนหัวที่ถูกต้องในการทำงานร่วมกับสคริปต์ NPH (ไม่มีการแยกส่วนหัว) นี่เป็นสิ่งสำคัญที่จะใช้กับเซิร์ฟเวอร์บางเครื่องที่คาดว่าสคริปต์ทั้งหมดของพวกเขาจะเป็น NPH พารามิเตอร์ - charset สามารถใช้เพื่อควบคุมชุดอักขระที่ส่งไปยังเบราเซอร์ หากไม่ได้ให้ค่าเริ่มต้น ISO-8859-1 เป็นผลข้างเคียงนี้ชุด charset () วิธีการเช่นกัน พารามิเตอร์การประกอบสามารถนำมาใช้เพื่อเปลี่ยนหน้าลงในไฟล์แนบ แทนที่จะแสดงเพจเบราว์เซอร์บางประเภทจะแจ้งให้ผู้ใช้บันทึกลงในดิสก์ ค่าของอาร์กิวเมนต์เป็นชื่อที่แนะนำสำหรับไฟล์ที่บันทึกไว้ เพื่อให้การทำงานนี้คุณอาจต้องตั้งค่าประเภท - applicationoctet-stream พารามิเตอร์ - p3p จะเพิ่มแท็ก P3P ไปยังส่วนหัวขาออก พารามิเตอร์สามารถเป็น arrayref หรือสตริงที่คั่นด้วยสตริงของแท็ก P3P ตัวอย่างเช่น: ในทั้งสองกรณีส่วนหัวขาออกจะมีรูปแบบดังนี้: CGI. pm จะยอมรับส่วนหัวหลายบรรทัดที่ถูกต้องเมื่อแต่ละบรรทัดถูกแยกออกด้วยค่า CRLF (rn บนแพลตฟอร์มส่วนใหญ่) ตามด้วยพื้นที่อย่างน้อยหนึ่งช่อง ตัวอย่างเช่น: อินพุตส่วนหัวของหลายบรรทัดไม่ถูกต้องจะเรียกใช้เป็นข้อยกเว้น เมื่อได้รับส่วนหัวหลายบรรทัด CGI. pm จะส่งกลับเป็นแถวเดียวตามกฎการพับของ RFC 2616: บรรทัดใหม่จะถูกลบออกในขณะที่พื้นที่สีขาวยังคงอยู่ การสร้างส่วนหัวการเปลี่ยนเส้นทางบางครั้งคุณไม่ต้องการสร้างเอกสารด้วยตนเอง แต่เพียงเปลี่ยนเส้นทางเบราว์เซอร์ที่อื่นอาจเลือก URL ตามช่วงเวลาของวันหรือข้อมูลประจำตัวของผู้ใช้ วิธีเปลี่ยนเส้นทาง () เปลี่ยนเส้นทางเบราว์เซอร์ไปยัง URL อื่น หากคุณใช้การเปลี่ยนเส้นทางเช่นนี้คุณไม่ควรพิมพ์ส่วนหัวด้วย คุณควรใช้ URL แบบเต็ม (รวมทั้ง http: หรือ ftp: part) ในคำขอเปลี่ยนเส้นทาง URL สัมพัทธ์จะไม่ทำงานอย่างถูกต้อง นอกจากนี้คุณยังสามารถใช้อาร์กิวเมนต์ที่ตั้งชื่อได้: อาร์กิวเมนต์ชื่อทั้งหมดที่รู้จักโดย header () ยังรู้จักโดย redirect () อย่างไรก็ตามส่วนหัว HTTP ส่วนใหญ่รวมถึงโฆษณาที่สร้างขึ้นโดย - cookie และ - target จะถูกละเว้นโดยเบราว์เซอร์ พารามิเตอร์ - nph ถ้าตั้งค่าเป็น true จะใช้ส่วนหัวที่ถูกต้องในการทำงานร่วมกับสคริปต์ NPH (ไม่มีการแยกส่วนหัว) นี่เป็นสิ่งสำคัญที่จะใช้กับเซิร์ฟเวอร์บางเครื่องเช่น Microsoft IIS ซึ่งคาดว่าสคริปต์ทั้งหมดของพวกเขาจะเป็น NPH พารามิเตอร์ - status จะกำหนดสถานะของการเปลี่ยนเส้นทาง HTTP กำหนดรหัสสถานะการเปลี่ยนเส้นทางที่เป็นไปได้สามแบบ: ค่าดีฟอลต์หากไม่ได้ระบุไว้คือ 302 ซึ่งหมายความว่าถูกย้ายชั่วคราว คุณสามารถเปลี่ยนสถานะเป็นรหัสสถานะอื่นได้หากต้องการ โปรดทราบว่าการเปลี่ยนสถานะเป็นสิ่งอื่นที่ไม่ใช่ 301, 302 หรือ 303 อาจทำให้การเปลี่ยนเส้นทางเปลี่ยนไป โปรดทราบว่าวลีที่มนุษย์สามารถอ่านได้คาดว่าจะมีอยู่เพื่อให้สอดคล้องกับ RFC 2616 ส่วน 6.1 การสร้างหัวเอกสาร HTML ขั้นตอนเริ่มต้น () จะสร้างส่วนบนสุดของหน้ารวมถึงข้อมูลเสริมที่ควบคุมลักษณะและลักษณะการทำงานของเพจ วิธีนี้จะส่งกลับส่วนหัว HTML แบบกระป๋องและแท็ก ltbodygt ที่เปิด พารามิเตอร์ทั้งหมดเป็นตัวเลือก ในรูปแบบพารามิเตอร์ที่ระบุพารามิเตอร์ที่รู้จัก ได้แก่ - ชื่อ, ผู้แต่ง, ฐานข้อมูล, ฐานข้อมูล, xbase, - dtd, - lang และ - target (ดูด้านล่างสำหรับคำอธิบาย) เพิ่มพารามิเตอร์ใด ๆ ที่คุณให้ไว้เช่นแอตทริบิวต์ BGCOLOR ที่ไม่เป็นทางการจะถูกเพิ่มลงในแท็ก ltbodygt พารามิเตอร์เพิ่มเติมต้องถูกดำเนินการโดยยัติภังค์ อาร์กิวเมนต์ - xbase ช่วยให้คุณสามารถระบุ HREF สำหรับแท็ก ltbasegt ที่แตกต่างจากที่ตั้งปัจจุบันได้เช่นเดียวกับในลิงก์ทั้งหมดของสัมพัทธ์จะถูกตีความเมื่อเทียบกับแท็กนี้ อาร์กิวเมนต์ - อาร์กิวเมนต์ช่วยให้คุณสามารถระบุกรอบเป้าหมายเริ่มต้นสำหรับลิงก์และแบบฟอร์มการกรอกข้อมูลทั้งหมดบนหน้าเว็บ This is a non-standard HTTP feature which only works with some browsers All relative links will be interpreted relative to this tag. You add arbitrary meta information to the header with the - meta argument. This argument expects a reference to a hash containing namevalue pairs of meta information. These will be turned into a series of header ltmetagt tags that look something like this: To create an HTTP-EQUIV type of ltmetagt tag, use - head . described below. The - style argument is used to incorporate cascading stylesheets into your code. See the section on CASCADING STYLESHEETS for more information. The - lang argument is used to incorporate a language attribute into the lthtmlgt tag. For example: The default if not specified is en-US for US English, unless the - dtd parameter specifies an HTML 2.0 or 3.2 DTD, in which case the lang attribute is left off. You can force the lang attribute to left off in other cases by passing an empty string (-langgt). The - encoding argument can be used to specify the character set for XHTML. It defaults to iso-8859-1 if not specified. The - dtd argument can be used to specify a public DTD identifier string. For example: Alternatively, it can take public and system DTD identifiers as an array: For the public DTD identifier to be considered, it must be valid. Otherwise it will be replaced by the default DTD. If the public DTD contains XHTML, CGI. pm will emit XML. The - declarexml argument, when used in conjunction with XHTML, will put a ltxmlgt declaration at the top of the HTML header. The sole purpose of this declaration is to declare the character set encoding. In the absence of - declarexml, the output HTML will contain a ltmetagt tag that specifies the encoding, allowing the HTML to pass most validators. The default for - declarexml is false. You can place other arbitrary HTML elements to the ltheadgt section with the - head tag. For example, to place a ltlinkgt element in the head section, use this: To incorporate multiple HTML elements into the ltheadgt section, just pass an array reference: And heres how to create an HTTP-EQUIV ltmetagt tag: JAVASCRIPTING: The - script . - noScript . - onLoad . - onMouseOver . - onMouseOut and - onUnload parameters are used to add JavaScript calls to your pages. - script should point to a block of text containing JavaScript function definitions. This block will be placed within a ltscriptgt block inside the HTML (not HTTP) header. The block is placed in the header in order to give your page a fighting chance of having all its JavaScript functions in place even if the user presses the stop button before the page has loaded completely. CGI. pm attempts to format the script in such a way that JavaScript-naive browsers will not choke on the code: unfortunately there are some browsers, such as Chimera for Unix, that get confused by it nevertheless. The - onLoad and - onUnload parameters point to fragments of JavaScript code to execute when the page is respectively opened and closed by the browser. Usually these parameters are calls to functions defined in the - script field: Use the - noScript parameter to pass some HTML text that will be displayed on browsers that do not have JavaScript (or browsers where JavaScript is turned off). The ltscriptgt tag, has several attributes including type, charset and src. src allows you to keep JavaScript code in an external file. To use these attributes pass a HASH reference in the - script parameter containing one or more of - type, - src, or - code: A final feature allows you to incorporate multiple ltscriptgt sections into the header. Just pass the list of script sections as an array reference. this allows you to specify different source files for different dialects of JavaScript. Example: The option - language is a synonym for - type, and is supported for backwards compatibility. The old-style positional parameters are as follows: The authors e-mail address (will create a ltlink revMADEgt tag if present A true flag if you want to include a ltbasegt tag in the header. This helps resolve relative addresses to absolute ones when the document is moved, but makes the document hierarchy non-portable. Use with care Other parameters you want to include in the ltbodygt tag may be appended to these. This is a good place to put HTML extensions, such as colors and wallpaper patterns. ENDING THE HTML DOCUMENT: This ends an HTML document by printing the ltbodygtlthtmlgt tags. CREATING A SELF-REFERENCING URL THAT PRESERVES STATE INFORMATION: selfurl() will return a URL, that, when selected, will reinvoke this script with all its state information intact. This is most useful when you want to jump around within the document using internal anchors but you dont want to disrupt the current contents of the form(s). Something like this will do the trick. If you want more control ove r whats returned, using the url() method instead. You can also retrieve the unprocessed query string with querystring(): The behavior of calling querystring is currently undefined when the HTTP method is something other than GET. OBTAINING THE SCRIPTS URL url() returns the scripts URL in a variety of formats. Called without any arguments, it returns the full form of the URL, including host name and port number You can modify this format with the following named arguments: If true, produce an absolute URL, e. g. Produce a relative URL. This is useful if you want to reinvoke your script with different parameters. For example: Produce the full URL, exactly as if called without any arguments. This overrides the - relative and - absolute arguments. Append the additional path information to the URL. This can be combined with - full . - absolute or - relative . - pathinfo is provided as a synonym. Append the query string to the URL. This can be combined with - full . - absolute or - relative . - querystring is provided as a synonym. Generate just the protocol and net location, as in foo:8000 If Apaches modrewrite is turned on, then the script name and path info probably wont match the request that the user sent. Set - rewritegt1 (default) to return URLs that match what the user sent (the original request URI). Set - rewritegt0 to return URLs that match the URL after modrewrites rules have run. MIXING POST AND URL PARAMETERS It is possible for a script to receive CGI parameters in the URL as well as in the fill-out form by creating a form that POSTs to a URL containing a query string (a mark followed by arguments). The param() method will always return the contents of the POSTed fill-out form, ignoring the URLs query string. To retrieve URL parameters, call the urlparam() method. Use it in the same way as param() . The main difference is that it allows you to read the parameters, but not set them. Under no circumstances will the contents of the URL query string interfere with similarly-named CGI parameters in POSTed forms. If you try to mix a URL query string with a form submitted with the GET method, the results will not be what you expect. CREATING STANDARD HTML ELEMENTS: CGI. pm defines general HTML shortcut methods for many HTML tags. HTML shortcuts are named after a single HTML element and return a fragment of HTML text. Example: This results in the following HTML code (extra newlines have been added for readability): If you find the syntax for calling the HTML shortcuts awkward, you can import them into your namespace and dispense with the object syntax completely (see the next section for more details): PROVIDING ARGUMENTS TO HTML SHORTCUTS The HTML methods will accept zero, one or multiple arguments. If you provide no arguments, you get a single tag: If you provide one or more string arguments, they are concatenated together with spaces and placed between opening and closing tags: If the first argument is a hash reference, then the keys and values of the hash become the HTML tags attributes: You may dispense with the dashes in front of the attribute names if you prefer: Sometimes an HTML tag attribute has no argument. For example, ordered lists can be marked as COMPACT. The syntax for this is an argument that that points to an undef string: Prior to CGI. pm version 2.41, providing an empty () string as an attribute argument was the same as providing undef. However, this has changed in order to accommodate those who want to create tags of the form ltimg altgt. The difference is shown in these two pieces of code: THE DISTRIBUTIVE PROPERTY OF HTML SHORTCUTS One of the cool features of the HTML shortcuts is that they are distributive. If you give them an argument consisting of a reference to a list, the tag will be distributed across each element of the list. For example, heres one way to make an ordered list: This example will result in HTML output that looks like this: This is extremely useful for creating tables. For example: HTML SHORTCUTS AND LIST INTERPOLATION Consider this bit of code: It will ordinarily return the string that you probably expect, namely: Note the space between the element Hi and the element mom. CGI. pm puts the extra space there using array interpolation, which is controlled by the magic variable. Sometimes this extra space is not what you want, for example, when you are trying to align a series of images. In this case, you can simply change the value of to an empty string. I suggest you put the code in a block as shown here. Otherwise the change to will affect all subsequent code until you explicitly reset it. NON-STANDARD HTML SHORTCUTS A few HTML tags dont follow the standard pattern for various reasons. comment() generates an HTML comment (lt-- comment --gt). Call it like Because of conflicts with built-in Perl functions, the following functions begin with initial caps: In addition, starthtml(), endhtml(), startform(), endform(), startmultipartform() and all the fill-out form tags are special. See their respective sections. AUTOESCAPING HTML By default, all HTML that is emitted by the form-generating functions is passed through a function called escapeHTML(): escapedstring escapeHTML(unescaped string) Escape HTML formatting characters in a string. Provided that you have specified a character set of ISO-8859-1 (the default), the standard HTML escaping rules will be used. The lt character becomes amplt, gt becomes ampgt, amp becomes ampamp, and the quote character becomes ampquot. In addition, the hexadecimal 0x8b and 0x9b characters, which some browsers incorrectly interpret as the left and right angle-bracket characters, are replaced by their numeric character entities (amp8249 and amp8250). If you manually change the charset, either by calling the charset() method explicitly or by passing a - charset argument to header(), then all characters will be replaced by their numeric entities, since CGI. pm has no lookup table for all the possible encodings. escapeHTML ( ) expects the supplied string to be a character string. This means you should Encode::decode data received from outside and Encode::encode your strings before sending them back outside. If your source code UTF-8 encoded and you want to upgrade string literals in your source to character strings, you can use use utf8. See perlunitut. perlunifaq and perlunicode for more information on how Perl handles the difference between bytes and characters. The automatic escaping does not apply to other shortcuts, such as h1(). You should call escapeHTML() yourself on untrusted data in order to protect your pages against nasty tricks that people may enter into guestbooks, etc. To change the character set, use charset(). To turn autoescaping off completely, use autoEscape(0): Get or set the current character set. Get or set the value of the autoescape flag. PRETTY-PRINTING HTML By default, all the HTML produced by these functions comes out as one long line without carriage returns or indentation. This is yuck, but it does reduce the size of the documents by 10-20. To get pretty-printed output, please use CGI::Pretty. a subclass contributed by Brian Paulsen. CREATING FILL-OUT FORMS: General note The various form-creating methods all return strings to the caller, containing the tag or tags that will create the requested form element. You are responsible for actually printing out these strings. Its set up this way so that you can place formatting tags around the form elements. Another note The default values that you specify for the forms are only used the first time the script is invoked (when there is no query string). On subsequent invocations of the script (when there is a query string), the former values are used even if they are blank. If you want to change the value of a field from its previous value, you have two choices: (1) call the param() method to set it. (2) use the - override (alias - force) parameter (a new feature in version 2.15). This forces the default value to be used, regardless of the previous value: Yet another note By default, the text and labels of form elements are escaped according to HTML rules. This means that you can safely use ltCLICK MEgt as the label for a button. However, it also interferes with your ability to incorporate special HTML character sequences, such as ampAacute, into your fields. If you wish to turn off automatic escaping, call the autoEscape() method with a false value immediately after creating the CGI object: Note that autoEscape() is exclusively used to effect the behavior of how some CGI. pm HTML generation functions handle escaping. Calling escapeHTML() explicitly will always escape the HTML. A Lurking Trap Some of the form-element generating methods return multiple tags. In a scalar context, the tags will be concatenated together with spaces, or whatever is the current value of the global. In a list context, the methods will return a list of elements, allowing you to modify them if you wish. Usually you will not notice this behavior, but beware of this: endform() produces several tags, and only the first of them will be printed because the format only expects one value. CREATING AN ISINDEX TAG Prints out an ltisindexgt tag. ไม่น่าตื่นเต้นมาก The parameter - action specifies the URL of the script to process the query. The default is to process the query with the current script. STARTING AND ENDING A FORM startform() will return a ltformgt tag with the optional method, action and form encoding that you specify. The defaults are: endform() returns the closing ltformgt tag. Startform()s enctype argument tells the browser how to package the various fields of the form before sending the form to the server. Two values are possible: Note: These methods were previously named startform() and endform(). These methods are now DEPRECATED. Please use startform() and endform() instead. This is the older type of encoding. It is compatible with many CGI scripts and is suitable for short fields containing text data. For your convenience, CGI. pm stores the name of this encoding type in ampCGI::URLENCODED . This is the newer type of encoding. It is suitable for forms that contain very large fields or that are intended for transferring binary data. Most importantly, it enables the file upload feature. For your convenience, CGI. pm stores the name of this encoding type in ampCGI::MULTIPART Forms that use this type of encoding are not easily interpreted by CGI scripts unless they use CGI. pm or another library designed to handle them. If XHTML is activated (the default), then forms will be automatically created using this type of encoding. The startform() method uses the older form of encoding by default unless XHTML is requested. If you want to use the newer form of encoding by default, you can call startmultipartform() instead of startform() . The method endmultipartform() is an alias to endform() . JAVASCRIPTING: The - name and - onSubmit parameters are provided for use with JavaScript. The - name parameter gives the form a name so that it can be identified and manipulated by JavaScript functions. - onSubmit should point to a JavaScript function that will be executed just before the form is submitted to your server. You can use this opportunity to check the contents of the form for consistency and completeness. If you find something wrong, you can put up an alert box or maybe fix things up yourself. You can abort the submission by returning false from this function. Usually the bulk of JavaScript functions are defined in a ltscriptgt block in the HTML header and - onSubmit points to one of these function call. See starthtml() for details. FORM ELEMENTS After starting a form, you will typically create one or more textfields, popup menus, radio groups and other form elements. Each of these elements takes a standard set of named arguments. Some elements also have optional arguments. The standard arguments are as follows: The name of the field. After submission this name can be used to retrieve the fields value using the param() method. The initial value of the field which will be returned to the script after form submission. Some form elements, such as text fields, take a single scalar - value argument. Others, such as popup menus, take a reference to an array of values. The two arguments are synonyms. A numeric value that sets the order in which the form element receives focus when the user presses the tab key. Elements with lower values receive focus first. A string identifier that can be used to identify this element to JavaScript and DHTML. A boolean, which, if true, forces the element to take on the value specified by - value . overriding the sticky behavior described earlier for the - nosticky pragma. These are used to assign JavaScript event handlers. See the JavaScripting section for more details. Other common arguments are described in the next section. In addition to these, all attributes described in the HTML specifications are supported. CREATING A TEXT FIELD textfield() will return a text input field. The first parameter is the required name for the field (-name). The optional second parameter is the default starting value for the field contents (-value, formerly known as - default). The optional third parameter is the size of the field in characters (-size). The optional fourth parameter is the maximum number of characters the field will accept (-maxlength). As with all these methods, the field will be initialized with its previous contents from earlier invocations of the script. When the form is processed, the value of the text field can be retrieved with: If you want to reset it from its initial value after the script has been called once, you can do so like this: CREATING A BIG TEXT FIELD textarea() is just like textfield, but it allows you to specify rows and columns for a multiline text entry box. You can provide a starting value for the field, which can be long and contain multiple lines. CREATING A PASSWORD FIELD passwordfield() is identical to textfield(), except that its contents will be starred out on the web page. CREATING A FILE UPLOAD FIELD filefield() will return a file upload field. In order to take full advantage of this you must use the new multipart encoding scheme for the form. You can do this either by calling startform() with an encoding type of ampCGI::MULTIPART . or by calling the new method startmultipartform() instead of vanilla startform() . The first parameter is the required name for the field (-name). The optional second parameter is the starting value for the field contents to be used as the default file name (-default). For security reasons, browsers dont pay any attention to this field, and so the starting value will always be blank. Worse, the field loses its sticky behavior and forgets its previous contents. The starting value field is called for in the HTML specification, however, and possibly some browser will eventually provide support for it. The optional third parameter is the size of the field in characters (-size). The optional fourth parameter is the maximum number of characters the field will accept (-maxlength). JAVASCRIPTING: The - onChange . - onFocus . - onBlur . - onMouseOver . - onMouseOut and - onSelect parameters are recognized. See textfield() for details. PROCESSING A FILE UPLOAD FIELD When the form is processed, you can retrieve an IO::Handle compatible handle for a file upload field like this: In a list context, upload() will return an array of filehandles. This makes it possible to process forms that use the same name for multiple upload fields. If you want the entered file name for the file, you can just call param(): Different browsers will return slightly different things for the name. Some browsers return the filename only. Others return the full path to the file, using the path conventions of the users machine. Regardless, the name returned is always the name of the file on the users machine, and is unrelated to the name of the temporary file that CGI. pm creates during upload spooling (see below). When a file is uploaded the browser usually sends along some information along with it in the format of headers. The information usually includes the MIME content type. To retrieve this information, call uploadInfo(). It returns a reference to a hash containing all the document headers. If you are using a machine that recognizes text and binary data modes, be sure to understand when and how to use them (see the Camel book). Otherwise you may find that binary files are corrupted during file uploads. Accessing the temp files directly When processing an uploaded file, CGI. pm creates a temporary file on your hard disk and passes you a file handle to that file. After you are finished with the file handle, CGI. pm unlinks (deletes) the temporary file. If you need to you can access the temporary file directly. You can access the temp file for a file upload by passing the file name to the tmpFileName() method: The temporary file will be deleted automatically when your program exits unless you manually rename it. On some operating systems (such as Windows NT), you will need to close the temporary files filehandle before your program exits. Otherwise the attempt to delete the temporary file will fail. Handling interrupted file uploads There are occasionally problems involving parsing the uploaded file. This usually happens when the user presses Stop before the upload is finished. In this case, CGI. pm will return undef for the name of the uploaded file and set cgierror() to the string 400 Bad request (malformed multipart POST). This error message is designed so that you can incorporate it into a status code to be sent to the browser. Example: You are free to create a custom HTML page to complain about the error, if you wish. Progress bars for file uploads and avoiding temp files CGI. pm gives you low-level access to file upload management through a file upload hook. You can use this feature to completely turn off the temp file storage of file uploads, or potentially write your own file upload progress meter. This is much like the UPLOADHOOK facility available in Apache::Request. with the exception that the first argument to the callback is an Apache::Upload object, here its the remote filename. The data field is optional it lets you pass configuration information (e. g. a database handle) to your hook callback. The usetempfile field is a flag that lets you turn on and off CGI. pms use of a temporary disk-based file during file upload. If you set this to a FALSE value (default true) then q-gtparam(uploadedfile) will no longer work, and the only way to get at the uploaded data is via the hook you provide. If using the function-oriented interface, call the CGI::uploadhook() method before calling param() or any other CGI functions: This method is not exported by default. You will have to import it explicitly if you wish to use it without the CGI. prefix. Troubleshooting file uploads on Windows If you are using CGI. pm on a Windows platform and find that binary files get slightly larger when uploaded but that text files remain the same, then you have forgotten to activate binary mode on the output filehandle. Be sure to call binmode() on any handle that you create to write the uploaded file to disk. Older ways to process file uploads ( This section is here for completeness. if you are building a new application with CGI. pm, you can skip it. ) The original way to process file uploads with CGI. pm was to use param(). The value it returns has a dual nature as both a file name and a lightweight filehandle. This dual nature is problematic if you following the recommended practice of having use strict in your code. Perl will complain when you try to use a string as a filehandle. More seriously, it is possible for the remote user to type garbage into the upload field, in which case what you get from param() is not a filehandle at all, but a string. To solve this problem the upload() method was added, which always returns a lightweight filehandle. This generally works well, but will have trouble interoperating with some other modules because the file handle is not derived from IO::Handle. So that brings us to current recommendation given above, which is to call the handle() method on the file handle returned by upload(). That upgrades the handle to an IO::Handle. Its a big win for compatibility for a small penalty of loading IO::Handle the first time you call it. CREATING A POPUP MENU popupmenu() creates a menu. The required first argument is the menus name (-name). The required second argument (-values) is an array reference containing the list of menu items in the menu. You can pass the method an anonymous array, as shown in the example, or a reference to a named array, such as foo. The optional third parameter (-default) is the name of the default menu choice. If not specified, the first item will be the default. The values of the previous choice will be maintained across queries. Pass an array reference to select multiple defaults. The optional fourth parameter (-labels) is provided for people who want to use different values for the user-visible label inside the popup menu and the value returned to your script. Its a pointer to an hash relating menu values to user-visible labels. If you leave this parameter blank, the menu values will be displayed by default. (You can also leave a label undefined if you want to). The optional fifth parameter (-attributes) is provided to assign any of the common HTML attributes to an individual menu item. Its a pointer to a hash relating menu values to another hash with the attributes name as the key and the attributes value as the value. When the form is processed, the selected value of the popup menu can be retrieved using: CREATING AN OPTION GROUP Named parameter style optgroup() creates an option group within a popup menu. The required first argument ( - name ) is the label attribute of the optgroup and is not inserted in the parameter list of the query. The required second argument ( - values ) is an array reference containing the list of menu items in the menu. You can pass the method an anonymous array, as shown in the example, or a reference to a named array, such as foo. If you pass a HASH reference, the keys will be used for the menu values, and the values will be used for the menu labels (see - labels below). The optional third parameter ( - labels ) allows you to pass a reference to a hash containing user-visible labels for one or more of the menu items. You can use this when you want the user to see one menu string, but have the browser return your program a different one. If you dont specify this, the value string will be used instead (eenie, meenie and minie in this example). This is equivalent to using a hash reference for the - values parameter. An optional fourth parameter ( - labeled ) can be set to a true value and indicates that the values should be used as the label attribute for each option element within the optgroup. An optional fifth parameter (-novals) can be set to a true value and indicates to suppress the val attribute in each option element within the optgroup. An optional sixth parameter (-attributes) is provided to assign any of the common HTML attributes to an individual menu item. Its a pointer to a hash relating menu values to another hash with the attributes name as the key and the attributes value as the value. CREATING A SCROLLING LIST scrollinglist() creates a scrolling list. The first and second arguments are the list name (-name) and values (-values). As in the popup menu, the second argument should be an array reference. The optional third argument (-default) can be either a reference to a list containing the values to be selected by default, or can be a single value to select. If this argument is missing or undefined, then nothing is selected when the list first appears. In the named parameter version, you can use the synonym - defaults for this parameter. The optional fourth argument is the size of the list (-size). The optional fifth argument can be set to true to allow multiple simultaneous selections (-multiple). Otherwise only one selection will be allowed at a time. The optional sixth argument is a pointer to a hash containing long user-visible labels for the list items (-labels). If not provided, the values will be displayed. The optional sixth parameter (-attributes) is provided to assign any of the common HTML attributes to an individual menu item. Its a pointer to a hash relating menu values to another hash with the attributes name as the key and the attributes value as the value. When this form is processed, all selected list items will be returned as a list under the parameter name listname. The values of the selected items can be retrieved with: CREATING A GROUP OF RELATED CHECKBOXES checkboxgroup() creates a list of checkboxes that are related by the same name. The first and second arguments are the checkbox name and values, respectively (-name and - values). As in the popup menu, the second argument should be an array reference. These values are used for the user-readable labels printed next to the checkboxes as well as for the values passed to your script in the query string. The optional third argument (-default) can be either a reference to a list containing the values to be checked by default, or can be a single value to checked. If this argument is missing or undefined, then nothing is selected when the list first appears. The optional fourth argument (-linebreak) can be set to true to place line breaks between the checkboxes so that they appear as a vertical list. Otherwise, they will be strung together on a horizontal line. The optional - labels argument is a pointer to a hash relating the checkbox values to the user-visible labels that will be printed next to them. If not provided, the values will be used as the default. The optional parameters - rows . and - columns cause checkboxgroup() to return an HTML3 compatible table containing the checkbox group formatted with the specified number of rows and columns. You can provide just the - columns parameter if you wish checkboxgroup will calculate the correct number of rows for you. The option - disabled takes an array of checkbox values and disables them by greying them out (this may not be supported by all browsers). The optional - attributes argument is provided to assign any of the common HTML attributes to an individual menu item. Its a pointer to a hash relating menu values to another hash with the attributes name as the key and the attributes value as the value. The optional - tabindex argument can be used to control the order in which radio buttons receive focus when the user presses the tab button. If passed a scalar numeric value, the first element in the group will receive this tab index and subsequent elements will be incremented by one. If given a reference to an array of radio button values, then the indexes will be jiggered so that the order specified in the array will correspond to the tab order. You can also pass a reference to a hash in which the hash keys are the radio button values and the values are the tab indexes of each button. Examples: The optional - labelattributes argument will contain attributes attached to the ltlabelgt element that surrounds each button. When the form is processed, all checked boxes will be returned as a list under the parameter name groupname. The values of the on checkboxes can be retrieved with: The value returned by checkboxgroup() is actually an array of button elements. You can capture them and use them within tables, lists, or in other creative ways: CREATING A STANDALONE CHECKBOX checkbox() is used to create an isolated checkbox that isnt logically related to any others. The first parameter is the required name for the checkbox (-name). It will also be used for the user-readable label printed next to the checkbox. The optional second parameter (-checked) specifies that the checkbox is turned on by default. Synonyms are - selected and - on. The optional third parameter (-value) specifies the value of the checkbox when it is checked. If not provided, the word on is assumed. The optional fourth parameter (-label) is the user-readable label to be attached to the checkbox. If not provided, the checkbox name is used. The value of the checkbox can be retrieved using: CREATING A RADIO BUTTON GROUP radiogroup() creates a set of logically-related radio buttons (turning one member of the group on turns the others off) The first argument is the name of the group and is required (-name). The second argument (-values) is the list of values for the radio buttons. The values and the labels that appear on the page are identical. Pass an array reference in the second argument, either using an anonymous array, as shown, or by referencing a named array as in foo. The optional third parameter (-default) is the name of the default button to turn on. If not specified, the first item will be the default. You can provide a nonexistent button name, such as - to start up with no buttons selected. The optional fourth parameter (-linebreak) can be set to true to put line breaks between the buttons, creating a vertical list. The optional fifth parameter (-labels) is a pointer to an associative array relating the radio button values to user-visible labels to be used in the display. If not provided, the values themselves are displayed. All modern browsers can take advantage of the optional parameters - rows . and - columns . These parameters cause radiogroup() to return an HTML3 compatible table containing the radio group formatted with the specified number of rows and columns. You can provide just the - columns parameter if you wish radiogroup will calculate the correct number of rows for you. To include row and column headings in the returned table, you can use the - rowheaders and - colheaders parameters. Both of these accept a pointer to an array of headings to use. The headings are just decorative. They dont reorganize the interpretation of the radio buttons -- theyre still a single named unit. The optional - tabindex argument can be used to control the order in which radio buttons receive focus when the user presses the tab button. If passed a scalar numeric value, the first element in the group will receive this tab index and subsequent elements will be incremented by one. If given a reference to an array of radio button values, then the indexes will be jiggered so that the order specified in the array will correspond to the tab order. You can also pass a reference to a hash in which the hash keys are the radio button values and the values are the tab indexes of each button. Examples: The optional - attributes argument is provided to assign any of the common HTML attributes to an individual menu item. Its a pointer to a hash relating menu values to another hash with the attributes name as the key and the attributes value as the value. The optional - labelattributes argument will contain attributes attached to the ltlabelgt element that surrounds each button. When the form is processed, the selected radio button can be retrieved using: The value returned by radiogroup() is actually an array of button elements. You can capture them and use them within tables, lists, or in other creative ways: CREATING A SUBMIT BUTTON submit() will create the query submission button. Every form should have one of these. The first argument (-name) is optional. You can give the button a name if you have several submission buttons in your form and you want to distinguish between them. The second argument (-value) is also optional. This gives the button a value that will be passed to your script in the query string. The name will also be used as the user-visible label. You can use - label as an alias for - value. I always get confused about which of - name and - value changes the user-visible label on the button. You can figure out which button was pressed by using different values for each one: CREATING A RESET BUTTON reset() creates the reset button. Note that it restores the form to its value from the last time the script was called, NOT necessarily to the defaults. Note that this conflicts with the Perl reset() built-in. Use CORE::reset() to get the original reset function. CREATING A DEFAULT BUTTON defaults() creates a button that, when invoked, will cause the form to be completely reset to its defaults, wiping out all the changes the user ever made. CREATING A HIDDEN FIELD hidden() produces a text field that cant be seen by the user. It is useful for passing state variable information from one invocation of the script to the next. The first argument is required and specifies the name of this field (-name). The second argument is also required and specifies its value (-default). In the named parameter style of calling, you can provide a single value here or a reference to a whole list Fetch the value of a hidden field this way: Note, that just like all the other form elements, the value of a hidden field is sticky. If you want to replace a hidden field with some other values after the script has been called once youll have to do it manually: CREATING A CLICKABLE IMAGE BUTTON imagebutton() produces a clickable image. When its clicked on the position of the click is returned to your script as buttonname. x and buttonname. y, where buttonname is the name youve assigned to it. The first argument (-name) is required and specifies the name of this field. The second argument (-src) is also required and specifies the URL The third option (-align, optional) is an alignment type, and may be TOP, BOTTOM or MIDDLE Fetch the value of the button this way: x param(buttonname. x) y param(buttonname. y) CREATING A JAVASCRIPT ACTION BUTTON button() produces an ltinputgt tag with type quotbuttonquot. When its pressed the fragment of JavaScript code pointed to by the - onClick parameter will be executed. HTTP COOKIES Browsers support a so-called cookie designed to help maintain state within a browser session. CGI. pm has several methods that support cookies. A cookie is a namevalue pair much like the named parameters in a CGI query string. CGI scripts create one or more cookies and send them to the browser in the HTTP header. The browser maintains a list of cookies that belong to a particular Web server, and returns them to the CGI script during subsequent interactions. In addition to the required namevalue pair, each cookie has several optional attributes: 1. an expiration time This is a timedate string (in a special GMT format) that indicates when a cookie expires. The cookie will be saved and returned to your script until this expiration date is reached if the user exits the browser and restarts it. If an expiration date isnt specified, the cookie will remain active until the user quits the browser. This is a partial or complete domain name for which the cookie is valid. The browser will return the cookie to any host that matches the partial domain name. For example, if you specify a domain name of. capricorn, then the browser will return the cookie to Web servers running on any of the machines capricorn, www2.capricorn, feckless. capricorn, etc. Domain names must contain at least two periods to prevent attempts to match on top level domains like. edu. If no domain is specified, then the browser will only return the cookie to servers on the host the cookie originated from. If you provide a cookie path attribute, the browser will check it against your scripts URL before returning the cookie. For example, if you specify the path cgi-bin, then the cookie will be returned to each of the scripts cgi-bintally. pl, cgi-binorder. pl, and cgi-bincustomerservicecomplain. pl, but not to the script cgi-privatesiteadmin. pl. By default, path is set to , which causes the cookie to be sent to any CGI script on your site. If the secure attribute is set, the cookie will only be sent to your script if the CGI request is occurring on a secure channel, such as SSL. The interface to HTTP cookies is the cookie() method: cookie() creates a new cookie. Its parameters include: The name of the cookie (required). This can be any string at all. Although browsers limit their cookie names to non-whitespace alphanumeric characters, CGI. pm removes this restriction by escaping and unescaping cookies behind the scenes. The value of the cookie. This can be any scalar value, array reference, or even hash reference. For example, you can store an entire hash into a cookie this way: The optional partial path for which this cookie will be valid, as described above. The optional partial domain for which this cookie will be valid, as described above. The optional expiration date for this cookie. The format is as described in the section on the header() method: If set to true, this cookie will only be used within a secure SSL session. The cookie created by cookie() must be incorporated into the HTTP header within the string returned by the header() method: To create multiple cookies, give header() an array reference: To retrieve a cookie, request it by name by calling cookie() method without the - value parameter. This example uses the object-oriented form: Cookies created with a single scalar value, such as the riddlename cookie, will be returned in that form. Cookies with array and hash values can also be retrieved. The cookie and CGI namespaces are separate. If you have a parameter named answers and a cookie named answers, the values retrieved by param() and cookie() are independent of each other. However, its simple to turn a CGI parameter into a cookie, and vice-versa: If you call cookie() without any parameters, it will return a list of the names of all cookies passed to your script: See the cookie. cgi example script for some ideas on how to use cookies effectively. WORKING WITH FRAMES Its possible for CGI. pm scripts to write into several browser panels and windows using the HTML 4 frame mechanism. There are three techniques for defining new frames programmatically: 1. Create a ltFramesetgt document After writing out the HTTP header, instead of creating a standard HTML document using the starthtml() call, create a ltframesetgt document that defines the frames on the page. Specify your script(s) (with appropriate parameters) as the SRC for each of the frames. There is no specific support for creating ltframesetgt sections in CGI. pm, but the HTML is very simple to write. 2. Specify the destination for the document in the HTTP header You may provide a - target parameter to the header() method: This will tell the browser to load the output of your script into the frame named ResultsWindow. If a frame of that name doesnt already exist, the browser will pop up a new window and load your scripts document into that. There are a number of magic names that you can use for targets. See the HTML ltframegt documentation for details. 3. Specify the destination for the document in the ltformgt tag You can specify the frame to load in the FORM tag itself. With CGI. pm it looks like this: When your script is reinvoked by the form, its output will be loaded into the frame named ResultsWindow. If one doesnt already exist a new window will be created. The script frameset. cgi in the examples directory shows one way to create pages in which the fill-out form and the response live in side-by-side frames. SUPPORT FOR JAVASCRIPT The usual way to use JavaScript is to define a set of functions in a ltSCRIPTgt block inside the HTML header and then to register event handlers in the various elements of the page. Events include such things as the mouse passing over a form element, a button being clicked, the contents of a text field changing, or a form being submitted. When an event occurs that involves an element that has registered an event handler, its associated JavaScript code gets called. The elements that can register event handlers include the ltBODYgt of an HTML document, hypertext links, all the various elements of a fill-out form, and the form itself. There are a large number of events, and each applies only to the elements for which it is relevant. Here is a partial list: The browser is loading the current document. Valid in: The browser is closing the current page or frame. Valid for: The user has pressed the submit button of a form. This event happens just before the form is submitted, and your function can return a value of false in order to abort the submission. Valid for: The mouse has clicked on an item in a fill-out form. Valid for: The user has changed the contents of a field. Valid for: The user has selected a field to work with. Valid for: The user has deselected a field (gone to work somewhere else). Valid for: The user has changed the part of a text field that is selected. Valid for: The mouse has moved over an element. The mouse has moved off an element. In order to register a JavaScript event handler with an HTML element, just use the event name as a parameter when you call the corresponding CGI method. For example, to have your validateAge() JavaScript code executed every time the textfield named age changes, generate the field like this: This example assumes that youve already declared the validateAge() function by incorporating it into a ltSCRIPTgt block. The CGI. pm starthtml() method provides a convenient way to create this section. Similarly, you can create a form that checks itself over for consistency and alerts the user if some essential value is missing by creating it this way: print startform(-onSubmitgtvalidateMe(this)) See the javascript. cgi script for a demonstration of how this all works. LIMITED SUPPORT FOR CASCADING STYLE SHEETS CGI. pm has limited support for HTML3s cascading style sheets (css). To incorporate a stylesheet into your document, pass the starthtml() method a - style parameter. The value of this parameter may be a scalar, in which case it is treated as the source URL for the stylesheet, or it may be a hash reference. In the latter case you should provide the hash with one or more of - src or - code . - src points to a URL where an externally-defined stylesheet can be found. - code points to a scalar value to be incorporated into a ltstylegt section. Style definitions in - code override similarly-named ones in - src . hence the name cascading. You may also specify the type of the stylesheet by adding the optional - type parameter to the hash pointed to by - style . If not specified, the style defaults to textcss. To refer to a style within the body of your document, add the - class parameter to any HTML element: Or define styles on the fly with the - style parameter: You may also use the new span() element to apply a style to a section of text: Note that you must import the :html3 definitions to have the span() method available. Heres a quick and dirty example of using CSSs. See the CSS specification at w3.orgStyleCSS for more information. Pass an array reference to - code or - src in order to incorporate multiple stylesheets into your document. Should you wish to incorporate a verbatim stylesheet that includes arbitrary formatting in the header, you may pass a - verbatim tag to the - style hash, as follows: This will generate an HTML header that contains this: Any additional arguments passed in the - style value will be incorporated into the ltlinkgt tag. For example: To make more complicated ltlinkgt tags, use the Link() function and pass it to starthtml() in the - head argument, as in: To create primary and alternate stylesheet, use the - alternate option: If you are running the script from the command line or in the perl debugger, you can pass the script a list of keywords or parametervalue pairs on the command line or from standard input (you dont have to worry about tricking your script into reading from environment variables). You can pass keywords like this: To turn off this feature, use the - nodebug pragma. To test the POST method, you may enable full debugging with the - debug pragma. This will allow you to feed newline-delimited namevalue pairs to the script on standard input. When debugging, you can use quotes and backslashes to escape characters in the familiar shell manner, letting you place spaces and other funny characters in your parametervalue pairs: Finally, you can set the path info for the script by prefixing the first namevalue parameter with the path followed by a question mark (): DUMPING OUT ALL THE NAMEVALUE PAIRS The Dump() method produces a string consisting of all the querys namevalue pairs formatted nicely as a nested list. This is useful for debugging purposes: Produces something that looks like: As a shortcut, you can interpolate the entire CGI object into a string and it will be replaced with the a nice HTML dump shown above: FETCHING ENVIRONMENT VARIABLES Some of the more useful environment variables can be fetched through this interface. The methods are as follows: Return a list of MIME types that the remote browser accepts. If you give this method a single argument corresponding to a MIME type, as in Accept(texthtml), it will return a floating point value corresponding to the browsers preference for this type from 0.0 (dont want) to 1.0. Glob types (e. g. text) in the browsers accept list are handled correctly. Note that the capitalization changed between version 2.43 and 2.44 in order to avoid conflict with Perls accept() function. Returns the HTTPCOOKIE variable. Cookies have a special format, and this method call just returns the raw form (cookie dough). See cookie() for ways of setting and retrieving cooked cookies. Called with no parameters, rawcookie() returns the packed cookie structure. You can separate it into individual cookies by splitting on the character sequence . Called with the name of a cookie, retrieves the unescaped form of the cookie. You can use the regular cookie() method to get the names, or use the rawfetch() method from the CGI::Cookie module. Returns the HTTPUSERAGENT variable. If you give this method a single argument, it will attempt to pattern match on it, allowing you to do something like useragent(Mozilla) Returns additional path information from the script URL. เช่น. fetching cgi-binyourscriptadditionalstuff will result in pathinfo() returning additionalstuff. NOTE: The Microsoft Internet Information Server is broken with respect to additional path information. If you use the Perl DLL library, the IIS server will attempt to execute the additional path information as a Perl script. If you use the ordinary file associations mapping, the path information will be present in the environment, but incorrect. The best thing to do is to avoid using additional path information in CGI scripts destined for use with IIS. As per pathinfo() but returns the additional path information translated into a physical path, e. g. usrlocaletchttpdhtdocsadditionalstuff. The Microsoft IIS is broken with respect to the translated path as well. Returns either the remote host name or IP address. if the former is unavailable. Returns the remote host IP address, or 127.0.0.1 if the address is unavailable. scriptname() Return the script name as a partial URL, for self-referring scripts. referer() Return the URL of the page the browser was viewing prior to fetching your script. Not available for all browsers. Return the authorizationverification method in use for this script, if any. Returns the name of the server, usually the machines host name. When using virtual hosts, returns the name of the host that the browser attempted to contact Return the port that the server is listening on. Like serverport() except that it takes virtual hosts into account. Use this when running with virtual hosts. Returns the server software and version number. Return the authorizationverification name used for user verification, if this script is protected. Attempt to obtain the remote users name, using a variety of different techniques. This only works with older browsers such as Mosaic. Newer browsers do not report the user name for privacy reasons Returns the method used to access your script, usually one of POST, GET or HEAD. Returns the contenttype of data submitted in a POST, generally multipartform-data or applicationx-www-form-urlencoded Called with no arguments returns the list of HTTP environment variables, including such things as HTTPUSERAGENT, HTTPACCEPTLANGUAGE, and HTTPACCEPTCHARSET, corresponding to the like-named HTTP header fields in the request. Called with the name of an HTTP header field, returns its value. Capitalization and the use of hyphens versus underscores are not significant. For example, all three of these examples are equivalent: The same as http() . but operates on the HTTPS environment variables present when the SSL protocol is in effect. Can be used to determine whether SSL is turned on. USING NPH SCRIPTS NPH, or no-parsed-header, scripts bypass the server completely by sending the complete HTTP header directly to the browser. This has slight performance benefits, but is of most use for taking advantage of HTTP extensions that are not directly supported by your server, such as server push and PICS headers. Servers use a variety of conventions for designating CGI scripts as NPH. Many Unix servers look at the beginning of the scripts name for the prefix nph-. The Macintosh WebSTAR server and Microsofts Internet Information Server, in contrast, try to decide whether a program is an NPH script by examining the first line of script output. CGI. pm supports NPH scripts with a special NPH mode. When in this mode, CGI. pm will output the necessary extra header information when the header() and redirect() methods are called. The Microsoft Internet Information Server requires NPH mode. As of version 2.30, CGI. pm will automatically detect when the script is running under IIS and put itself into this mode. You do not need to do this manually, although it wont hurt anything if you do. However, note that if you have applied Service Pack 6, much of the functionality of NPH scripts, including the ability to redirect while setting a cookie, do not work at all on IIS without a special patch from Microsoft. See web. archive. orgweb20010812012030support. microsoftsupportkbarticlesQ280341.ASP Non-Parsed Headers Stripped From CGI Applications That Have nph - Prefix in Name. Simply add the - nph pragma to the list of symbols to be imported into your script: Call nph() with a non-zero parameter at any point after using CGI. pm in your program. in the header() and redirect() statements: Server Push CGI. pm provides four simple functions for producing multipart documents of the type needed to implement server push. These functions were graciously provided by Ed Jordan ltedfidalgogt. To import these into your namespace, you must import the :push set. You are also advised to put the script into NPH mode and to set to 1 to avoid buffering problems. Here is a simple script that demonstrates server push: This script initializes server push by calling multipartinit() . It then enters a loop in which it begins a new multipart section by calling multipartstart() . prints the current local time, and ends a multipart section with multipartend() . It then sleeps a second, and begins again. On the final iteration, it ends the multipart section with multipartfinal() rather than with multipartend() . Initialize the multipart system. The - boundary argument specifies what MIME boundary string to use to separate parts of the document. If not provided, CGI. pm chooses a reasonable boundary for you. Start a new part of the multipart document using the specified MIME type. If not specified, texthtml is assumed. End a part. You must remember to call multipartend() once for each multipartstart(), except at the end of the last part of the multipart document when multipartfinal() should be called instead of multipartend(). End all parts. You should call multipartfinal() rather than multipartend() at the end of the last part of the multipart document. Users interested in server push applications should also have a look at the CGI::Push module. Avoiding Denial of Service Attacks A potential problem with CGI. pm is that, by default, it attempts to process form POSTings no matter how large they are. A wily hacker could attack your site by sending a CGI script a huge POST of many megabytes. CGI. pm will attempt to read the entire POST into a variable, growing hugely in size until it runs out of memory. While the script attempts to allocate the memory the system may slow down dramatically. This is a form of denial of service attack. Another possible attack is for the remote user to force CGI. pm to accept a huge file upload. CGI. pm will accept the upload and store it in a temporary directory even if your script doesnt expect to receive an uploaded file. CGI. pm will delete the file automatically when it terminates, but in the meantime the remote user may have filled up the servers disk space, causing problems for other programs. The best way to avoid denial of service attacks is to limit the amount of memory, CPU time and disk space that CGI scripts can use. Some Web servers come with built-in facilities to accomplish this. In other cases, you can use the shell limit or ulimit commands to put ceilings on CGI resource usage. CGI. pm also has some simple built-in protections against denial of service attacks, but you must activate them before you can use them. These take the form of two global variables in the CGI name space: If set to a non-negative integer, this variable puts a ceiling on the size of POSTings, in bytes. If CGI. pm detects a POST that is greater than the ceiling, it will immediately exit with an error message. This value will affect both ordinary POSTs and multipart POSTs, meaning that it limits the maximum size of file uploads as well. You should set this to a reasonably high value, such as 1 megabyte. If set to a non-zero value, this will disable file uploads completely. Other fill-out form values will work as usual. You can use these variables in either of two ways. Set the variable at the top of the script, right after the use statement: Open up CGI. pm, find the definitions for POSTMAX and DISABLEUPLOADS, and set them to the desired values. Youll find them towards the top of the file in a subroutine named initializeglobals(). An attempt to send a POST larger than POSTMAX bytes will cause param() to return an empty CGI parameter list. You can test for this event by checking cgierror() . either after you create the CGI object or, if you are using the function-oriented interface, call ltparam()gt for the first time. If the POST was intercepted, then cgierror() will return the message 413 POST too large. This error message is actually defined by the HTTP protocol, and is designed to be returned to the browser as the CGI scripts status code. For example: However it isnt clear that any browser currently knows what to do with this status code. It might be better just to create an HTML page that warns the user of the problem. COMPATIBILITY WITH CGI-LIB. PL To make it easier to port existing programs that use cgi-lib. pl the compatibility routine ReadParse is provided. Porting is simple: CGI. pms ReadParse() routine creates a tied variable named in, which can be accessed to obtain the query variables. Like ReadParse, you can also provide your own variable. Infrequently used features of ReadParse, such as the creation of in and in variables, are not supported. Once you use ReadParse, you can retrieve the query object itself this way: This allows you to start using the more interesting features of CGI. pm without rewriting your old scripts from scratch. An even simpler way to mix cgi-lib calls with CGI. pm calls is to import both the. cgi - lib and. standard method: Cgi-lib functions that are available in CGI. pm In compatibility mode, the following cgi-lib. pl functions are available for your use: Cgi-lib functions that are not available in CGI. pm AUTHOR INFORMATION The CGI. pm distribution is copyright 1995-2007, Lincoln D. Stein. It is distributed under GPL and the Artistic License 2.0. It is currently maintained by Mark Stosberg with help from many contributors. Address bug reports and comments to: rt. cpan. orgPublicDistDisplay. htmlQueueCGI. pm When sending bug reports, please provide the version of CGI. pm, the version of Perl, the name and version of your Web server, and the name and version of the operating system you are using. If the problem is even remotely browser dependent, please provide information about the affected browsers as well. Thanks very much to: Matt Heffron (heffronfalstaff. css. beckman) James Taylor (james. taylorsrs. gov) Scott Anguish ltsanguishdigifixgt Mike Jewell (mlj3uvirginia. edu) Timothy Shimmin (teskbs. citri. edu. au) Joergen Haegg (jhaxis. se) Laurent Delfosse (delfossedelfosse) Richard Resnick (applepi1aol) Craig Bishop (csbbarwonwater. vic. gov. au) Tony Curtis (tcvcpc. univie. ac. at) Tim Bunce (Tim. Bunceig. co. uk) Tom Christiansen (tchristconvex) Andreas Koenig (kfranz. ww. TU-Berlin. DE) Tim MacKenzie (Tim. MacKenziefulcrum. au) Kevin B. Hendricks (kbhenddogwood. tyler. wm. edu) Stephen Dahmen (joyfireinxpress) Ed Jordan (edfidalgo) David Alan Pisoni (davidcnation) Doug MacEachern (dougmopengroup. org) Robin Houston (robinoneworld. org) . and many many more. for suggestions and bug fixes. A COMPLETE EXAMPLE OF A SIMPLE FORM-BASED SCRIPT Please report them. CGI::Carp - provides a Carp implementation tailored to the CGI environment. CGI::Fast - supports running CGI applications under FastCGI CGI::Pretty - pretty prints HTML generated by CGI. pm (with a performance penalty)

No comments:

Post a Comment