1 / 22

PHP 프로그래밍 8 장 쿠키와 세션 9 장 웹사이트 초기 화면 제작

PHP 프로그래밍 8 장 쿠키와 세션 9 장 웹사이트 초기 화면 제작. 서국화 kookhwa@kunsan.ac.kr 군산대학교 통계컴퓨터과학과 정보과학기술 연구실 2012. 4. 18. 목 차. 쿠키 세션 완성된 웹 사이트 웹 사이트 초기 화면. 쿠키 (1/4). 쿠키 사용자가 웹 서버에 접속하여 로그인 하였을 때 사용자의 컴퓨터에 저장되는 특정 정보 사이트의 어떤 페이지에서도 로그인된 상태와 로그인된 아이디 이용 가능

velma
Download Presentation

PHP 프로그래밍 8 장 쿠키와 세션 9 장 웹사이트 초기 화면 제작

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. PHP 프로그래밍8장 쿠키와 세션9장 웹사이트 초기 화면 제작 서국화 kookhwa@kunsan.ac.kr 군산대학교 통계컴퓨터과학과 정보과학기술 연구실 2012. 4. 18

  2. 목 차 쿠키 세션 완성된 웹 사이트 웹 사이트 초기 화면 IST (Information Sciences & Technology) Laboratory

  3. 쿠키(1/4) • 쿠키 • 사용자가 웹 서버에 접속하여 로그인 하였을 때 사용자의 컴퓨터에 저장되는 특정 정보 • 사이트의 어떤 페이지에서도 로그인된 상태와 로그인된 아이디 이용 가능 • 만약 쿠키라는 개념이 없다면 로그인 시 로그인 상태와 로그인 아이디를 DB에 써 넣어야함 IST (Information Sciences & Technology) Laboratory

  4. 함수의 인자 설명 name 쿠기의 이름 value 쿠키의 값 expire 쿠키가 유효한 시간 path '/home/' 이라고 설정하면 ‘/home/' 디렉토리와 서브 디렉토리에서 쿠키를 사용 가능. domain 쿠키를 이용할 수 있는 도메인을 의미 secure TRUE 로 설정하면 접속에서만 쿠키가 설정 쿠키(2/4) 성공적으로 쿠키가 만들어지면 true, 실패하면 false를 반환함 boolsetcookie ( string name [, string value [, intexpire [, string path [, string domain [, boolsecure]]]]] ) • 쿠키 생성과 삭제 • setcookie() IST (Information Sciences & Technology) Laboratory

  5. 쿠키(3/4) 현재시간을 의미, 현재부터 8초간 쿠키가 유지됨 <?     $cookie_r1 = setcookie("userid", "hkd", time()+8);     $cookie_r2 = setcookie("username", "홍길동", time()+8);        if ( $cookie_r1 and $cookie_r2)          echo "쿠키 생성이 완료 되었습니다(단, 생성된 쿠키는 8초간 지속됩니다)."; ?> 쿠키이름 쿠키값 쿠키 유효시간 쿠키 생성 IST (Information Sciences & Technology) Laboratory

  6. 쿠키(4/4) <? setcookie("userid");      // userid쿠키 삭제 setcookie("username");// username 쿠키 삭제      echo "생성된 'userid' 쿠키 : ".$_COOKIE[userid]."<br>";       echo "생성된 'username' 쿠키 : ".$_COOKIE[username]."<br>"; ?> • 쿠키 삭제 • 쿠키이름만 주고 값을 지정하지 않으면 쿠키가 삭제됨 IST (Information Sciences & Technology) Laboratory

  7. 세션(1/5) • 세션의 개념 • 쿠키가 로그인 정보를 클라이언트 컴퓨터에 저장하는데 반하여 세션에서는 보안상 로그인 정보를 서버에 저장 • PHP 4에서 추가 되었고 웹 사이트에 연속적으로 접속할 때 이전의 접속 정보를 이용할 수 있는 방법을 제공 • 서버에서 세션 아이디라고 부르는 유일한 아이디를 부여하여 서버의 특정 디렉토리에 저장 • 세션 아이디는 또한 클라이언트 컴퓨터에 저장되거나 URL를 통하여 클라이언트에게 전달됨 IST (Information Sciences & Technology) Laboratory

  8. 세션(2/5) • 세션의 초기화 • session_start( ) 함수 • 세션을 생성할 뿐 아니라 세션 아이디를 활성화시킴 • 함수의 리턴 값은 항상 TRUE IST (Information Sciences & Technology) Laboratory

  9. 세션(3/5) <? session_start();    echo '세션이 시작되었습니다.<br><br>';    $_SESSION['color'] = 'blue';    $_SESSION['animal']  = 'dog';    $_SESSION['time']    = time();    echo "<a href='session2.php'>session2.php로 이동</a>"; ?> 세션의 등록 IST (Information Sciences & Technology) Laboratory

  10. 세션(4/5) <? session_start();    echo '세션이 시작되었습니다.<br><br>';    echo $_SESSION['color'].'<br>';    echo $_SESSION['animal'].'<br>';     echo date('Y-m-d(H:i:s)', $_SESSION['time']); ?> 세션 사용 IST (Information Sciences & Technology) Laboratory

  11. 세션(6/5) <? session_start(); unset($_SESSION['color']); unset($_SESSION['dog']); unset($_SESSION['time']); if ($_SESSION['color'] and $_SESSION['dog'] and $_SESSION['time']) { echo $_SESSION['color'].'<br>'; echo $_SESSION['dog'].'<br>'; echo $_SESSION['time'].'<br>'; } else echo "세션 변수가 모두 삭제 되었습니다."; ?> 세션 삭제 IST (Information Sciences & Technology) Laboratory

  12. 완성된 웹 사이트 완성된 홈페이지 IST (Information Sciences & Technology) Laboratory

  13. 웹 사이트 초기 화면(1/9) 초기화면 IST (Information Sciences & Technology) Laboratory

  14. 웹 사이트 초기 화면(2/9) 초기화면 IST (Information Sciences & Technology) Laboratory

  15. 웹 사이트 초기 화면(3/9) • 사용되는 3개 파일 index.php : 메인 화면의 틀 top.php   : 메인 화면의 상단 프레임(메뉴 부분) main_init.php : 메인 화면의 하단 프레임(메인 부분) 초기 홈페이지 프레임 구성 IST (Information Sciences & Technology) Laboratory

  16. 웹 사이트 초기 화면(4/9) <html>    <head>   <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ks_c_5601-1987">     <title>:: PHP 프로그래밍 입문에 오신 것을 환영합니다~~ ::</title>    </head>     <frameset framespacing="0" border="0" frameborder="0“ rows="210, *">      <frame name="top" src="top.php" scrolling="auto" noresize>    <frame name="main" src="main_init.php" scrolling="auto" noresize>     </frameset>   </html> 프레임 틀 만들기 IST (Information Sciences & Technology) Laboratory

  17. 웹 사이트 초기 화면(5/9) <?      session_start(); ?> // 세션 변수 초기화 <html>    <head>     <title>:: PHP 프로그래밍 입문에 오신것을 환영합니다~~ ::</title>     <link rel="stylesheet" href="style.css" type="text/css">    </head>   <body leftmargin="0" topmargin="0" marginwidth="0“ marginheight="0">    <table width="776" align="center" cellspacing="0" cellpadding="0" border="0">     <tr><td>       <table width=776 cellspacing="0" cellpadding="0" border="0"> <!—상단제목그림-->          <tr> <td colspan="10"> //열개의 열을 하나로 합침              <img border="0" src="img/sub_title.gif" width="776"  height="146"></td></tr> <tr><td height="8" colspan="10"> <img border="0" src="img/blank.gif" width="1" height="8"></td> </tr> <!--메뉴 시작--> <TR> 상단 프레임 만들기 IST (Information Sciences & Technology) Laboratory

  18. 웹 사이트 초기 화면(6/9) <TD> <a href="main.php" target="main"> <img SRC="img/menu_01.gif" WIDTH=87 HEIGHT=47 border=0 ALT=""></a></TD> <?       if (!$userid)       {           echo "<TD>               <a href='login/login_form.html'  target='main'>               <img SRC='img/menu_02.gif' WIDTH=87 HEIGHT=47 border=0 ALT='""></a></TD> ;       }       else       {           echo " <TD>              <a href='login/logoff.php'  target='main'>              <img SRC='img/menu_10.gif' WIDTH=87 HEIGHT=47 border=0 ALT=""></a></TD>” ;       } 상단 프레임 만들기 IST (Information Sciences & Technology) Laboratory

  19. 웹 사이트 초기 화면(7/9)   if (!$userid)     {    echo "     <TD>       <a href='login/member_form.html'  target='main'>       <img SRC='img/menu_03.gif' WIDTH=84 HEIGHT=47  border=0 ALT=''></a></TD> ";     }     else     { echo "           <TD>       <a href='login/modify_memberinfo.php'  target='main'>             <img SRC='img/menu_11.gif' WIDTH=84 HEIGHT=47 border=0 ALT=''></a></TD> ";     } ?> <TD>               <a href="guestbook/guestbook.php"  target="main">               <img SRC="img/menu_04.gif" WIDTH=86 HEIGHT=47 border=0 ALT=""></a></TD>           <TD>       <a href="freeboard/list.php"  target="main">       <img SRC="img/menu_05.gif" WIDTH=86 HEIGHT=47 border=0 ALT=""></a></TD>           <TD> 상단 프레임 만들기 IST (Information Sciences & Technology) Laboratory

  20. 웹 사이트 초기 화면(8/9)                 <a href="notice/list.php"  target="main">               <img SRC="img/menu_06.gif" WIDTH=90 HEIGHT=47 border=0 ALT=""></a></TD>             <TD>               <a href="qna/list.php"  target="main">               <img SRC="img/menu_07.gif" WIDTH=85 HEIGHT=47 border=0 ALT=""></a></TD>      <TD>        <a href="down/list.php"  target="main">        <img SRC="img/menu_08.gif" WIDTH=88 HEIGHT=47  border=0 ALT=""></a></TD>           <TD>        <a href="survey/survey.php"  target="main">        <img SRC="img/menu_09.gif" WIDTH=89 HEIGHT=47  border=0 ALT=""></a></TD>    </TR> </table>             </td>          </tr>      </table> <!--메뉴끝--> </body> </html> 상단 프레임 만들기 IST (Information Sciences & Technology) Laboratory

  21. 웹 사이트 초기 화면(9/9) <html> <head>   <title> :: PHP 프로그래밍 입문에 오신 것을 환영합니다~~ :: </title>   <link rel="stylesheet" href="style.css" type="text/css"> </head> <body leftmargin="0" topmargin="0" marginwidth="0“ marginheight="0">  <table width="776" align="center" cellspacing="0" cellpadding="0“ border="0">  <tr height=150><td></td></tr>   <tr align=center>   <td>   메인화면 입니다.</td></tr>   </table>   </body>   </html> 초기 하단프레임 만들기 IST (Information Sciences & Technology) Laboratory

  22. 감사합니다 서국화 kookhwa@kunsan.ac.kr

More Related