1 / 19

CGI 실습 [4 번째 시간 ]

CGI 실습 [4 번째 시간 ]. 목 차. 실습 준비 chmod 755 ?? CGI 실습 1~3 방명록 실습. 1. 실습 준비. 자기 계정에 대한 755 permission 설정 cd .. chmod 755 [ 자기 아이디 ] HTML 파일 작성은 / public_html 디렉터리에 !! CGI 파일 작성은 / public_html / cgi -bin 디렉터리에 !!. 1. 실습 준비. 만약 디렉터리가 없다면 ? 만들자 !! cd ~

osmond
Download Presentation

CGI 실습 [4 번째 시간 ]

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CGI 실습 [4번째 시간]

  2. 목 차 • 실습 준비 • chmod 755 ?? • CGI 실습 1~3 • 방명록 실습

  3. 1. 실습 준비 • 자기 계정에 대한 755permission 설정 • cd .. • chmod 755 [자기 아이디] • HTML 파일 작성은 • /public_html디렉터리에!! • CGI 파일 작성은 • /public_html/cgi-bin 디렉터리에!!

  4. 1. 실습 준비 • 만약 디렉터리가 없다면? 만들자!! • cd ~ • mkdir –p public_html/cgi-bin • public_html과 cgi-bin 에도 755permission 설정 • chmod –R 755 public_html

  5. 2. chmod 755 ?? • 왜 권한을 755로 설정하는 것일까? [2진수 표현] 1 (=allow) 0 (=deny)

  6. 2. chmod 755 ?? (cont’) • 755로 가능한 것은?? IE / Firefox / Safari (= others) Owner / 7 rwx CGI HTML Others / 5 r-x Group / 5 r-x

  7. 3. CGI 실습 1~3 • cgi파일은 • /public_html/cgi-bin에서 작성!! • html 파일은 • /public_html에서 작성!! • vi가 어려워요 ;ㅁ; • 윈도우에서 메모장으로 작성 후 ftp로 알맞은 경로에 업로드 후 컴파일 및 실행\

  8. 3-1. CGI 실습 1 • 당연히 /public_html/cgi-bin 에서 작성!! > vi test1.c #include <stdio.h> void main() { printf("Content-type: text/html \n\n"); printf(" test #1 O.K.\n"); printf(" C-program example.\n"); }

  9. 3-1. CGI 실습 1 (cont’) • 이제컴파일과 권한 설정!! > gcc –o test1.cgi test1.c > chmod 755 test1.cgi

  10. 3-1. CGI 실습 1 (cont’) • /public_html에서 작성!! > vi index.html <HTML> <HEAD> <TITLE>CGI를 이용한 출 </TITLE></HEAD> <BODY> <A HREF = "./cgi-bin/test1.cgi"> CGI 예제1 </A> </BODY> </HTML>

  11. 3-2. CGI 실습 2 • 당연히 /public_html/cgi-bin 에서 작성!! > vi test1.c #! /bin/sh echo "Content-type: text/html"; echo; echo "test #2 (shell) also O.K. !!! "; echo; date

  12. 3-2. CGI 실습 2 (cont’) • 이제권한 설정!! > chmod 755 test1.cgi

  13. 3-2. CGI 실습 2 (cont’) • /public_html에서 작성!! > vi index.html <HTML> <HEAD> <TITLE>CGI를 이용한 출 </TITLE></HEAD> <BODY> <A HREF = "./cgi-bin/test2.cgi"> CGI 예제2 </A> </BODY> </HTML>

  14. 3-3. CGI 실습 3 • 당연히 /public_html/cgi-bin 에서 작성!! > vi test1.c #! /bin/sh echo "Content-type: text/html"; echo; echo "<HTML>"; echo "<Body>"; echo "<H2> 환경 변수의 값 </H2>"; echo "<HR>"; echo "SERVER_NAME : " $SERVER_NAME; echo "REQUEST_METHOD : " $REQUEST_METHOD; echo "</Body>"; echo "</HTML>";

  15. 3-2. CGI 실습 3 (cont’) • 이제권한 설정!! > chmod 755 test1.cgi

  16. 3-2. CGI 실습 3 (cont’) • /public_html에서 작성!! > vi index.html <HTML> <HEAD> <TITLE>CGI를 이용한 출 </TITLE></HEAD> <BODY> <A HREF = "./cgi-bin/test3.cgi"> CGI 예제2 </A> </BODY> </HTML>

  17. 4. 방명록 실습 • 교재 467~469 페이지 • 방명록 실습에 필요한 파일 • /public_html/guest_book/ • guest.html • /cgi-bin • write_guest_book.c • util.c • util.h

  18. 4. 방명록 실습 (cont’) • 컴파일 방법 • gcc –o write_guest_book.cgi write_guest_book.cutil.c • 추가해야 할 행 • write_guest_book.c • #include”./util.h” • 수정해야 할 행 • html 문서 • <form action=“../cgi-bin/write_guest_book.cgi” method=“post”>

  19. 4. 방명록 실습 (cont’) • 이번에는 777 이다!! > chmod 777 guest.html • cgi는 서버의 로컬 파일에 내용을 저장 • 즉, 파일을 다루는 함수(fprintf() / fscanf()등 사용) 를 사용해서 접근 • 실제로 html 폼에 있는 내용이 파일에 저장이 되려면? • 당연히 파일을 쓸수있는(write)권한이 있어야 돼!! • 그럼 755  777 • util.c / util.h등 실습 관련 파일 다운로드 • http://arkii.tistory.com/

More Related