div: 3 span: 4 h1,..., h6: (heading) h1 h2 </tag1> table: table tr (table row) tr td (table data) ol, ul: (ordered) (unordered) </tag4> 1: HTML

Similar documents
h1,..., h6: (heading) h1 h2 table: table tr (table row) tr td (table data) ol, ul: (ordered) (unordered) </tag1> </tag4> 1: HTML [1] html: Web HTML he

div: 3 span: 4 h1,..., h6: (heading) h1 h2 </tag1> table: table tr (table row) tr td (table data) ol, ul: (ordered) (unordered) </tag4> 1: HTML

~/WWW-local/compIID (WWW IID ) $ mkdir WWW-local $ cd WWW-local $ mkdir compiid 3. Emacs index.html n (a) $ cd ~/WWW/compIID

ii II Web Web HTML CSS PHP MySQL Web Web CSS JavaScript Web SQL Web

オンラインテスト

6 2 1

World Wide Web =WWW Web ipad Web Web HTML hyper text markup language CSS cascading style sheet Web Web HTML CSS HTML

ohp.mgp

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV


6 2 s µ µµµ µµµµ µ µ h µs µ µµµµ µ µ µ s mµµµµµ µµµ µµ µ u m µmµµµµµ µµ µ µ µ µ µ µ µ µ s 1

経営論集2011_07_小松先生.indd

07_経営論集2010 小松先生.indd

HTML文書の作成

54 5 PHP Web hellow.php 1:<?php 2: echo "Hellow, PHP!Y=n"; 3:?> echo PHP C 2: printf("hellow, PHP!Y=n"); PHP (php) $ php hellow.php Hellow, PHP! 5.1.2

( )

pdf

JavaScript 1.! DOM Ajax Shelley Powers,, JavaScript David Flanagan, JavaScript 2

演習室の PC のハードディスクには演習で作成したデータは保管できません 各 PC の ネットワーク接続 ショートカットからメディア情報センターのサーバーにアクセスしてください (Z ドライブとして使用できます ) 講義で使うフォルダ 2/23


untitled

hands_on_4.PDF

2009 Web B012-1

II 2 p.2 2 GET POST form action URL Aisatsu 2.1 Servlet GET GET : Query String QueryStringTest.java 1 import java.io.ioexception; 2 import java.io.pri

演習室の PC のハードディスクには演習で作成したデータは保管できません 各 PC の ネットワーク接続 ショートカットからメディア情報センターのサーバーにアクセスしてください (Z ドライブとして使用できます ) Web プログラミング 1 CGI (3 章 ) 2012/6/12( 水 ) 講義


untitled


1

情報システム設計論II ユーザインタフェース(1)


C G I 入 門 講 座

Web



0序文‐1章.indd

第3回_416.ppt

JavaScript演習


Condition DAQ condition condition 2 3 XML key value


double float

Microsoft PowerPoint - 04WWWとHTML.pptx


slide5.pptx

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

(search: ) [1] ( ) 2 (linear search) (sequential search) 1

VQT3B86-4 DMP-HV200 DMP-HV150 μ μ l μ


HTML web HTML HTML


PowerPoint プレゼンテーション

untitled

untitled

WEB DB PRESS Vol.1 65

Web apache

B 20 Web

soturon2013

Network Computing の基礎

JavaScript 演習 2 1

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( )

演習室の PC のハードディスクには演習で作成したデータは保管できません 各 PC の ネットワーク接続 ショートカットからメディア情報センターのサーバーにアクセスしてください (Z ドライブとして使用できます ) 演習名 使用するフォルダ 演習 1 Z: Web データ管理 演習

untitled

5-5_arai_JPNICSecSemi_XssCsrf_CM_ PDF

<4D F736F F D A957A A A8FEE95F18F88979D DEC90AC E646F63>

Web±ÜÍ÷¤Î³Ú¤·¤µ¤ò¹â¤á¤ëWeb¥Ú¡¼¥¸²ÄÄ°²½¥·¥¹¥Æ¥à

Web プログラミング 1 JavaScript (4) (4 章 ) 2013/7/17( 水 ) 日時 講義内容 4/10 ( 水 ) ガイダンス Web (1 章 ) 4/17 ( 水 ) HTML+CSS (1) (2 章 ) 4/24 ( 水 ) HTML+CSS (2) (2 章 ) 5

PowerPoint Presentation

jquery

wide94.dvi

インターネット技術特論 CGI 動的文書生成 C:CGI による動的文書生成 (C 言語 ) 山口実靖 課題 ( ろ ) 本学 Web サーバに自作 CGI プログラムを公開し, その URL とプログラムをメー

CodeIgniter Con 2011, Tokyo Japan, February

untitled

PFS-Readme

untitled

3 Powered by mod_perl, Apache & MySQL use Item; my $item = Item->new( id => 1, name => ' ', price => 1200,

JavaScript の使い方

■新聞記事

<td width=99%><input type="file" size="80" name="file"></td> <td width=1% nowrap align=right valign=top> 削除キー : </td> <td width=99%><input type="passw


_IMv2.key

SVG資料第10回目(その2) Ajaxによる同期通信と非同期通信の違い

PowerPoint Presentation

インターネットマガジン1996年3月号―INTERNET magazine No.14

2 / 16 HTML=HyperText Markup Language( ハイパーテキストマークアップランゲージ ) ブラウザ (Chrome) での表示 ソースの表示 ( メモ帳 /TeraPad) HTML <========= =========>


エレクトーンのお客様向けiPhone/iPad接続マニュアル

iPhone/iPad接続マニュアル

22 (266) / Web PF-Web Web Web Web / Web Web PF-Web Web Web Web CGI Web Web 1 Web PF-Web Web Perl C CGI A Pipe/Filter Architecture Based Software Gener

¥Í¥Ã¥È¥ï¡¼¥¯¥×¥í¥°¥é¥ß¥ó¥°ÆÃÏÀ

CSS CSS


Introduction to Information and Communication Technology (a)

Web情報システム 第1章~第5章

Microsoft Word - C.....u.K...doc

Webデザイン論

! "#$%&'()*+,-. STUV WXYZ[\]^_`abcdefghijklmno pqrstuvwxyz{ }~ ƒ ˆ Š Œ Ž š œ žÿ ª«±²³ µ ¹º»¼½¾ ÀÁÂÃÄ ÅÆÇÈÉÊËÌÍÎÏÐ

Introduction Purpose This training course demonstrates the use of the High-performance Embedded Workshop (HEW), a key tool for developing software for

96 8 PHPlot 1. ( 8.1) 4 1: // 2: // $_SERVER[ HTTP_REFERER ]... 3: // $_SERVER[ HTTP_USER_AGENT ]... 4: // $_SERVER[ REMOTE_ADDR ]... ( ) 5: // $_SERV

Java

Transcription:

HTML CSS JavaScript CGI, PHP 1 Web HTML (Hyper-Text Markup Language)[1] CSS (Cascading Style Sheets)[2, 3] JavaScript ([4]) CGI (Common Gateway Interface)[5], PHP[6] HTML Web Web PHP 5, 7 Web 2 Web GUI CUI 1 GUI OS GUI GUI Web GUI OS OS Web 3 HTML 3.1 HTML WWW (World Wide Web, Web) Web Web HTML HTML Web HTML HTML HTML 4 2014 10 28 HTML5[9] HTML5 Web HTML5 4 3.2 HTML 2 1 1 2 CSS[3] 1/17

div: 3 span: 4 h1,..., h6: (heading) h1 h2 </tag1> table: table tr (table row) tr td (table data) ol, ul: (ordered) (unordered) </tag4> 1: 3.2.1 HTML tag_name <tag_name> tag_name </tag_name> / HTML [1] html: Web HTML head: HTML body: HTML title: HTML p: (paragraph) a: href li: ol ul form: CGI form input: CGI textarea: select: img: (image) src br: (break line) p hr: (horizontal) meta: head HTML <HTML>... </HTML> <html>... </html> XHTML html 3 4 2/17

1: HTML 1 <html> <head> 3 <t i t l e>simple web page</ t i t l e> </head> 5 <body> <h1>chapter 1</h1> 7 <h2>s e c t i o n 1</h2> <p>paragraph 1.</p> 9 <p>paragraph 2 : b e f o r e br.<br> a f t e r br.</p> 11 <h2>s e c t i o n 2</h2> <p>f o o bar.</p> 13 <hr> 15 <h1>chapter 2</h1> 17 <h2>s e c t i o n 1</h2> <h2>s e c t i o n 19 </body> </html> 2</h2> body HTML html html head body HTML html html HTML 1 Firefox 2 2: HTML action: form CGI method: form http-equiv: meta content: meta style: CSS 3.2.2 HTML [1] id: ID ID name: id ID form href: a a src: img 3.3 HTML 1 HTML HTML-lint[10] HTML HTML 2 Firefox 3 4 CSS CSS[2] Cascading Style Sheets HTML 3/17

2: HTML <!DOCTYPE HTML PUBLIC 2 " //W3C//DTD HTML 4. 0 1 T r a n s i t i o n a l //EN"> <html lang=" j a "> 4 <head> <meta http equiv=" Content type " 6 content=" t e x t / html ; c h a r s e t=utf 8"> <t i t l e> HTML </ t i t l e> 8 </head> 10 <body> <div id="toc"> 12 <ol> < l i><a href="#c1"> 1 </a> 14 <ul> < l i><a href="#c1. S1 ">1. 1 </a></ l i> 16 < l i><a href="#c1. S2 ">1. 2 </a></ l i> </ ul> 18 </ l i> < l i><a href="#c2"> 2 </a> 20 <ul> < l i><a href="#c2. S1 ">2. 1 </a></ l i> 22 < l i><a href="#c2. S2 ">2. 2 </a></ l i> </ ul> 24 </ l i> </ ol> 26 </ div> 28 <hr> 30 <div> <h1 id="c1"> 1 </h1> 32 <h2 id="c1. S1 ">1. 1 </h2> <p> 1 </p> 34 <p> 2 <br> </p> 36 <h2 id="c1. S2 ">1. 2 </h2> 38 <p> </p> </ div> 40 <hr> 42 <div> 44 <h1 id="c2"> 2 </h1> <h2 id="c2. S1 ">2. 1 </h2> 46 <h2 id="c2. S2 ">2. 2 </h2> </ div> 48 </body> 50 </html> HTML HTML CSS CSS HTML CSS CSS CSS CSS HTML CSS CSS 3: HTML h1 h1 HTML class id top, left, color CSS CSS3[3] HTML 4/17

Web 5 JavaScript JavaScript [4] C JavaScript JavaScript HTML HTML HTML onclick innertext HTML id WebAPI document.getelementbyid JavaScript jquery.js[11] Prototype[12] Web Node.js[13] JavaScript 6 CGI 6.1 CGI Web Web JavaScript Web Ajax Web CGI 4: Google Ajax CGI CGI Ajax Web form CGI Google[14] HTML 4 form 6.2 Web CGI CGI 1. Web CGI 2. CGI 3. Web CGI Web CGI Ajax Web 5/17

time user 1. 7. browser 2. 6. Web server (httpd) Web server (CGI program) 5: CGI Web 1. Web 2. Web Web 3. Web CGI 4. CGI 5. Web CGI 6. Web CGI 7. Web Web 5 6.3 HTML CGI form form action CGI method HTML URL [15] form CGI 3. 5. 4. 6.3.1 method form method method GET, POST 5 1 GET 6 CGI GET GET POST 6.3.2 form textarea input select CGI 3 name textarea select (option) input type 2 textarea : select : option value input : type radio, checkbox, hidden value 1. URL URL [15] 2. (=) 5 6 Web URL 6/17

1: GET POST method URL ( ) GET POST type text password radio checkbox file hidden submit reset 2: input form CGI form 3. (&) CGI 3 hoge fuga bar 2 CGI hoge=3&bar=fuga 6.4 C CGI CGI Perl, PHP, Python, Ruby C 6.4.1 CGI HTML 3 CGI HTML 4 6.4.2 CGI [5] REQUEST_METHOD POST GET 3 stdlib.h getenv REQUEST_METHOD URL CGI 5 6.4.3 cgilib CGI 1. & 2. = 3. URL cgilib[16] 7/17

3: CGI / 1 6 / 2 #include <s t d i o. h> 4 #include <time. h> #include <s t d l i b. h> 6 #define HTML_HEADER(CHAR_SET) \ 8 " Content type : t e x t / html ; c h a r s e t=" CHAR_SET " \n\n " 10 int main ( void ) { 12 const time_t now = time (NULL) ; / ( c f. man a time ) / int num ; 14 srand ( ( unsigned )now ) ; / / 16 num = rand ( ) % 6 + 1 ; / / 18 / UTF 8 / 20 puts (HTML_HEADER( "UTF 8" ) ) ; puts ( "<html><body>" ) ; 22 / HTML / 24 p r i n t f ( "<p>seed = %l d ; d i c e = %d</p>\n ", now, num ) ; 26 puts ( "<form a c t i o n =\"/~ inamoto / cgi bin /CGI d i c e. c g i \" method=\"get\">\n " " <input type =\" submit \" value =\" \">\n " 28 "</form>" "</html></body>" ) ; 30 return 0 ; 32 4: CGI HTML <html> 2 <head> <meta http equiv=" Content type " content=" t e x t / html ; c h a r s e t=utf 8"> 4 <t i t l e> CGI </ t i t l e> </head> 6 <body> 8 <form action=" /~ inamoto / cgi bin /CGI d i c e. c g i " method="get"> 10 </form> </body> 12 </html> <input type=" submit " value=""> cgilib GPL[17] cgilib 2 GPL ; 2 GPL ; cgilib 2 ; GPL GPL cgilib CGI 6 A HTML 7 HTML textarea <form action="http://somewhere/virus.cgi" method="get"><input type="submit" value=" 8/17

REQUEST_METHOD QUERY_STRING CONTENT_LENGTH PATH_INFO 3: CGI form method GET POST URL CGI GET? "></form> CGI http://somewhere/virus.cgi CGI form CGI 6.4.4 cgilib CGI CGI CGI type hidden input 8 CGI type hidden HTML CGI 7 PHP PHP[6] [7], [8] 7.1 C CGI Web Web Web HTML PHP [6] HTTP 7 PHP C Perl 8 Web htmlspecialchars CGI $_SERVER, $_GET, $_POST cookie CGI MySQL PostgreSQL, SQLite [8] 7.2 PHP Web CGI PHP 9 PHP PHP ssh.cs.ehime-u.ac.jp ~inamoto/public_html/ Firefox http: //ssh.cs.ehime-u.ac.jp/~inamoto/test.php PHP 7 8 9/17

5: CGI / / 2 #include <s t d i o. h> 4 #include <s t d l i b. h> #include <s t r i n g. h> 6 #include <e r r n o. h> #include <a s s e r t. h> 8 #define HTML_HEADER(CHAR_SET) \ 10 " Content type : t e x t / html ; c h a r s e t=" CHAR_SET " \n\n " 12 int main ( void ) { 14 int data_size ; / / char buf = NULL; / / 16 char cp ; 18 puts (HTML_HEADER( "UTF 8" ) ) ; / Web UTF 8 / puts ( "<html><body>" ) ; 20 / POST / 22 i f ( ( cp = getenv ( "REQUEST_METHOD" ) ) && (! strcmp ( cp, "POST" ) ) ) { cp = getenv ( "CONTENT_LENGTH" ) ; / / 24 a s s e r t ( cp ) ; data_size = a t o i ( cp ) ; / / 26 buf = ( char ) malloc ( data_size + 1 ) ; / \0 +1 / cp = f g e t s ( buf, data_size + 1, s t d i n ) ; / / 28 buf [ data_size ] = \0 ; else i f ( cp && (! strcmp ( cp, "GET" ) ) ) { 30 / GET / cp = getenv ( "QUERY_STRING" ) ; 32 a s s e r t ( cp ) ; data_size = s t r l e n ( cp ) ; / / 34 buf = ( char ) malloc ( data_size + 1 ) ; / \0 +1 / memcpy( buf, cp, data_size + 1 ) ; / / 36 else { f p r i n t f ( s t d e r r, " i n v a l i d method : %s \n ", cp ) ; 38 e x i t (EXIT_FAILURE ) ; 40 / / 42 p r i n t f ( " form data f o l l o w s :<br>\n " ) ; f p u t s ( buf, stdout ) ; 44 puts ( " \n</body></html>" ) ; 46 f r e e ( buf ) ; / / 48 return 0 ; 50 9: PHP PHP 1 <?php phpinfo ( ) ;?> PHP php -l test.php PHP CGI php test.php PHP CGI php -S localhost:8080 test.php -t. GET curl -G -d hoge=fuga http://localhost:8080/test.php curl http://localhost:8080/test.php?hoge=fuga POST PUT curl 7.3 PHP PHP PHP <?php?> 10/17

10: PHP hello world <?php 2 echo h e l l o php. PHP_EOL; $lang = php ; 4 echo " h e l l o h e l l o { $lang ". PHP_EOL;?> 9 1 (;) C /* */ #// 1 echo print 10 <?php echo...?><?=...?> ( ) (") $ C int x = 1;PHP $x = 1; { PHP hello world 10 PHP_EOL PHP. 7.4 PHP $_SERVER 11 CGI REQUEST_METHOD $_SERVER[ REQUEST_METHOD ] CGI GET, POST var $_GET[ var ], $_POST[ var ] 9 PHP?> 10 print_r var_dump 11 array Perl POST $_FILES type file input name name upfile $upfile_array = $_FILES[ upfile ] $upfile_array[ size ] 7.5 PHP CGI C PHP C CGI PHP 3 PHP CGI 11 5 12 6 13 8 HTML Web [18] C CGI cgilib PHP GPL GPL [19] A cgilib CGI ~user ~user/workspace/cgi/src sample.c sample.c cgilib cgi.h #include <cgi.h> CGI ~user/public_html/cgi-bin sample.cgi 11/17

CGI cgilib CGI 1. cgilib [16] ~user/workspace/cgi/src cgilib 0.7 ~user/workspace/cgi/src/cgilib-0.7.tar.gz 2. (a) cd ~user/workspace/cgi/src (b) tar zxvf cgilib-0.7.tar.gz ~user/workspace/cgi/src/cgilib-0.7 3. cgilib cgi.c, aux.c, cookies.c (a) gcc -I cgilib-0.7 -o ~user/public_html/cgi-bin/sample.cgi sample.c cgilib-0.7/cgi.c cgilib-0.7/aux.c cgilib-0.7/cookies.c [1] HTML 4.01 Specification: http://www.w3.org/tr/ html401/ 2014 3 21. [2] Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification: https://www.w3.org/tr/css2/ 2016 4 12. [3] Cascading Style Sheets home page: https://www. w3.org/style/css/ 2016 4 12. [4] JavaScript Mozilla Developer Network: https://developer.mozilla.org/ja/docs/ Web/JavaScript 2016 4 12 [6] PHP: Hypertext Preprocessor, http://www.php. net [7] Kevin Tatroe ( ), Peter MacIntyre ( ), Rasmus Lerdorf ( ), ( ): PHP, (2014). [8] PHP : http://jp2.php.net/manual/ ja/ [9] HTML5: https://www.w3.org/tr/html5/ 2016 4 12 [10] : Another HTML-lint gateway, http: //cetus.sakura.ne.jp/htmllint/htmllint.html 2014 3 21. [11] jquery: http://jquery.com/ 2016 4 12 [12] Prototype: http://prototypejs.org/ 2016 4 12 [13] Node.js : https://nodejs.org/en/ 2016 4 12 [14] Google, Inc.: http://www.google.co.jp/ 2014 3 26. [15] URL Character Encoding Issues: http://tools. ietf.org/html/rfc1738#section-2.2 2014 3 21. [16] Lightweight CGI Library: http://www.infodrom. org/projects/cgilib/ 2014 4 2 [17] GNU : http://sourceforge.jp/projects/opensource/ wiki/licenses\%2fgnu_general_public_license 2014 4 2 [18] WWW : http://www.tohoho-web. com/www.htm 2014 4 3 [19] : http://itpro.nikkeibp.co.jp/ article/opinion/20061124/254769/?st=network 2014 4 3 [5] The WWW Common Gateway Interface 1.1: http://tools.ietf.org/html/ draft-robinson-www-interface-00 2014 3 27 12/17

6: cgilib CGI / 2 Copyright (C) INAMOTO Tsutomu & Ehime U n i v e r s i t y 4 This program i s f r e e s o f t w a r e ; you can r e d i s t r i b u t e i t and/ or modify i t under the terms of the GNU General Public License 6 as p u b l i s h e d by t h e Free Software Foundation ; e i t h e r v e r s i o n 2 of the License, or ( at your option ) any l a t e r version. 8 This program i s d i s t r i b u t e d in t h e hope t h a t i t w i l l be u s e f u l, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General P u b l i c License f o r more d e t a i l s. 14 You should have r e c e i v e d a copy o f t h e GNU General P u b l i c License along with t h i s program ; i f not, write to the Free Software 16 Foundation, Inc., 59 Temple Place Suite 330, Boston, MA 02111 1307, USA. / 18 / GPL / 20 #include <s t d l i b. h> 22 #include <s t d i o. h> #include <s t r i n g. h> 24 #include <errno. h> 26 #include <c g i. h> 28 int main ( int argc, char argv ) { 30 s_cgi c g i ; char vars, f i l e s ; 32 int i ; 34 c g i = c g i I n i t ( ) ; / c g i l i b / cgisettype ( " t e x t / html ; c h a r s e t=utf 8" ) ; / UTF 8 / 36 cgiheader ( ) ; / HTTP / 38 puts ( "<html><body>" ) ; 40 v a r s = c g i G e t V a r i a b l e s ( c g i ) ; / / i f ( v a r s ) { 42 puts ( "<p> </p>\n<dl>" ) ; for ( i = 0 ; v a r s [ i ] ; i ++) { 44 / / p r i n t f ( "<dt>%s</dt>\n<dd>%s</dd>\n ", v a r s [ i ], cgigetvalue ( c g i, v a r s [ i ] ) ) ; 46 puts ( "</dl>" ) ; 48 c g i F r e e L i s t ( v a r s ) ; / / 50 52 f i l e s = c g i G e t F i l e s ( c g i ) ; / / i f ( f i l e s ) { 54 puts ( "<p> </p>\n<dl>" ) ; for ( i = 0 ; f i l e s [ i ] ; i ++) { 56 s _ f i l e f i l e v a r ; char b u f f e r [ 1 0 2 4 ] ; 58 FILE f p ; char e1, e2 ; 60 f i l e v a r = c g i G e t F i l e ( c g i, f i l e s [ i ] ) ; 62 p r i n t f ( "<dt> : %s ; : %s</dt>\n<dd>", ( e1 = c g i E s c a p e ( f i l e v a r >f i l e n a m e ) ), ( e2 = c g i E s c a p e ( f i l e v a r >t m p f i l e ) ) ) ; 64 f r e e ( e1 ) ; f r e e ( e2 ) ; / cgiescape / 66 i f (! ( f p = fopen ( f i l e v a r >t m p f i l e, " r " ) ) ) { / / p r i n t f ( " f a i l e d i n opening f i l e : %s<br>\n ", s t r e r r o r ( e r r n o ) ) ; 68 e x i t (EXIT_FAILURE ) ; 70 while ( f g e t s ( b u f f e r, s i z e o f ( b u f f e r ), f p ) ) { / / p r i n t f ( "%s ", b u f f e r ) ; / \n / 72 f c l o s e ( f p ) ; 74 puts ( "</dd></dl>" ) ; 76 c g i F r e e L i s t ( f i l e s ) ; 78 puts ( "</body></html>" ) ; 80 c g i F r e e ( c g i ) ; / / 82 return EXIT_SUCCESS ; 84 13/17

7: CGI HTML <html> 2 <head> <meta http equiv=" Content type " content=" t e x t / html ; c h a r s e t=utf 8"> 4 <t i t l e>c g i dump</ t i t l e> </head> 6 <body> 8 <h1> GET</h1> <form action=" /~ inamoto / cgi bin /CGI decoded dump. c g i " method="get"> 10 <h2>i n p u t</h2> <ul> 12 < l i>type t e x t <input type=" t e x t " value=" i n p u t p l z. " name="get t e x t "> </ l i> 14 < l i>type password <input type=" password " value=" password p l z. " name="get password "> </ l i> 16 < l i>type r a d i o <input type=" r a d i o " value=" yes " name=" ">yes <input type=" r a d i o " checked value=" " name=" "> 18 </ l i> < l i>type checkbox 20 <input type=" checkbox " value=" apple " name="get checkbox ">apple <input type=" checkbox " value=" " name="get checkbox "> <input type=" checkbox " value=" " name="get checkbox "> </ l i> 22 < l i>type hidden <input type=" hidden " value=" hidden v a l u e " name="get hidden "> </ l i> 24 </ ul> 26 <h2>t e x t a r e a</h2> <textarea name="get t e x t a r e a "></ textarea> 28 <h2>s e l e c t</h2> 30 <s e l e c t name="get s e l e c t "> <option value=" 1 ">1</ option> <option value=" o p t i o n 2 ">o p t i o n 2</ option> <option value=" 3 ">3</ option> 32 </ s e l e c t> <br> 34 <input type=" submit " value=" "> <input type=" r e s e t " value=" "> </form> 36 <hr> 38 <h1> POST</h1> 40 <form action=" /~ inamoto / cgi bin /CGI decoded dump. c g i " method="post"> <h2>i n p u t</h2> 42 <ul> < l i>type password 44 <input type=" password " value=" password p l z. " name="post password "> </ l i> 46 </ ul> 48 <h2>t e x t a r e a</h2> <textarea name="post t e x t a r e a "></ textarea> 50 <br> <input type=" submit " value=" "> <input type=" r e s e t " value=" "> 52 </form> 54 <hr> 56 <h2></h2> <form action=" /~ inamoto / cgi bin /CGI decoded dump. c g i " method="post" enctype=" multipart / form data "> 58 <h2>i n p u t</h2> <ul> 60 < l i>type t e x t <input type=" t e x t " value=" i n p u t p l z. " name=" form t e x t "> </ l i> 62 < l i>type password <input type=" password " value=" password p l z. " name=" form password "> </ l i> 64 < l i>type r a d i o <input type=" r a d i o " value=" yes " name=" ">yes <input type=" r a d i o " checked value=" " name=" "> 66 </ l i> < l i>type checkbox <input type=" checkbox " value=" a p p le " name=" form checkbox ">a p p l e 68 <input type=" checkbox " value=" " name=" form checkbox "> <input type=" checkbox " value=" " name=" form checkbox "> 70 </ l i> < l i>type hidden <input type=" hidden " value=" hidden v a l u e " name=" form hidden "> 72 </ l i> < l i s t y l e=" font weight : bold ">type f i l e <input type=" f i l e " name=" form f i l e "> 74 </ l i> </ ul> 76 <br> <input type=" submit " value=" "> <input type=" r e s e t " value=" "> 78 </form> </body> 80 </html> 14/17

8: CGI / 2 Copyright (C) INAMOTO Tsutomu & Ehime U n i v e r s i t y 4 This program i s f r e e s o f t w a r e ; you can r e d i s t r i b u t e i t and/ or modify i t under t h e terms o f t h e GNU General P u b l i c License 6 as p u b l i s h e d by t h e Free Software Foundation ; e i t h e r v e r s i o n 2 o f t h e License, or ( at your o p t i o n ) any l a t e r v e r s i o n. 8 This program i s d i s t r i b u t e d in t h e hope t h a t i t w i l l be u s e f u l, 10 but WITHOUT ANY WARRANTY; w i t h o u t even t h e i m p l i e d warranty o f MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See t h e 12 GNU General P u b l i c License f o r more d e t a i l s. 14 You s h o u l d have r e c e i v e d a copy o f t h e GNU General P u b l i c License along with t h i s program ; i f not, w r i t e to t h e Free Software 16 Foundation, Inc., 59 Temple Place S u i t e 330, Boston, MA 02111 1307, USA. / 18 / / 20 #define VAR_NAME " remaining " 22 #define NEW_NAME " new_name" 24 #include <s t d i o. h> #include <s t d l i b. h> 26 #include <s t r i n g. h> #include <c g i. h> 28 int main ( void ) 30 { s_cgi c g i ; 32 char vars, cp ; char var_value [ 1 0 2 4 ] = " " ; / / 34 int i ; 36 c g i = c g i I n i t ( ) ; / c g i l i b / cgisettype ( " t e x t / html ; c h a r s e t=utf 8" ) ; / UTF 8 / 38 cgiheader ( ) ; / HTTP / 40 v a r s = c g i G e t V a r i a b l e s ( c g i ) ; / / i f ( v a r s ) { 42 for ( i = 0 ; v a r s [ i ] ; i ++) { i f (! strcmp ( v a r s [ i ], VAR_NAME) ) { 44 s t rncpy ( var_value, cgigetvalue ( cgi, VAR_NAME), s i z e o f ( var_value ) ) ; / / break ; 46 48 c g i F r e e L i s t ( v a r s ) ; / / 50 i f ( ( cp = cgigetvalue ( cgi, NEW_NAME) ) && strcmp ( cp, " " ) ) { / / 52 strncpy ( var_value, cp, s i z e o f ( var_value ) ) ; / / 54 p r i n t f ( "<html><body><p> %s = %s</p>", VAR_NAME, var_value ) ; / / 56 p r i n t f ( "<form a c t i o n =\"/~ inamoto / cgi bin /CGI hidden. c g i \" method=\"post\"> " ) ; p r i n t f ( " : <input type =\" t e x t \" value =\"\" name=\"%s \"> ", NEW_NAME) ; 58 i f ( strcmp ( var_value, " " ) ) { p r i n t f ( "<input type =\" hidden \" name=\"%s \" value=\"%s \"> ", 60 VAR_NAME, var_value ) ; / hidden / 62 puts ( "<input type =\" submit \" value =\" \"></form></body></html>" ) ; 64 c g i F r e e ( c g i ) ; / / 66 return EXIT_SUCCESS; 15/17

11: CGI PHP <html> 2 <body> <p>seed = <?php $now = time ( ) ; srand ( $now ) ; echo $now ;? >; 4 d i c e = <?= rand ( ) % 6 + 1?></p> 6 <form a c t i o n="<?= $_SERVER[ PHP_SELF ] ;?>" method="get"> <input type=" submit " value=" "> 8 </form> 10 </body> </html> 12: CGI PHP 1 <html> <body> 3 <p> = <?= $_SERVER[ REQUEST_METHOD ]?></p> 5 <pre> <?php 7 switch ($_SERVER[ REQUEST_METHOD ] ) { case GET : 9 var_dump($_get) ; break ; 11 case POST : var_dump($_post ) ; 13 break ; default : 15 die ( " i n v a l i d method : ". $_SERVER[ REQUEST_METHOD ] ) ; 17?> </pre> 19 </body> </html> 16/17

<html> 2 <body> 13: CGI PHP 4 <p> </p> <dl> 6 <?php 8 f u n c t i o n p ( $ s t r ) { r e t u r n urlencode ( htmlspecialchars ( $ s t r, ENT_QUOTES, UTF 8 ) ) ; 10 12 $var = $_SERVER[ REQUEST_METHOD ] ; POST === $var or GET === $var or die ( " i n v a l i d method={$var " ) ; 14 ### ( ) 16 foreach ( ${ _. $var as $var => $value ) { echo "<dt>{$var</dt><dd>". p ( $value ). </dd> ; 18?> 20 </dl> 22 <p> </p> <dl> 24 <?php foreach ( $_FILES as $key => $ary ) { $ d e s t = $ary [ name ] ; 26 $tmp = $ary [ tmp_name ] ; echo <dt> :. p ( $tmp ). ; :. p ( $ d e s t ). </dt> ; 28 $fh = fopen ( $tmp, " r " ) or die ( " f a i l e d i n opening f i l e : {$tmp " ) ; $cont = fread ( $fh, f i l e s i z e ( $tmp ) ) ; 30 f c l o s e ( $fh ) ; echo <dd><pre>, p ( $cont ), </pre></dd> ; 32 move_uploaded_file ( $tmp, $ d e s t ) or die ( " f a i l e d i n moving f i l e : {$tmp to { $ d e s t " ) ; 34?> </dl> 36 </body> </html> 17/17