LinkedNestBlog

PHP 문법 : 입출력 | FORM | HTTP

by 이진원Dev
PHP 문법 : 입출력 / FORM / HTTP


ref.] 생활코딩 > PHP > PHP 기본수업 > 입출력 그리고 폼과 HTTP
https://opentutorials.org/course/62/5125

  • Application Input Value
    • URL 을 통해 입력 데이터 받아오기
    • 예제
      • URL : http://127.0.0.1:8080/io_form/output_get.php?name=11111&pwd=12345
      • 파일명 : output_get.php
      • 소스파일
        1
        2
        3
        4
        5
        6
        7
        8
        <?php
        // http://127.0.0.1:8080/io_form/input_output.php?name=12345
        // id 파라미터를 url로서 입력받아 화면에 출력해주는 내용.
        echo $_GET['name'];
        echo '<br/>';
        // http://127.0.0.1:8080/io_form/input_output.php?name=12345&pwd=1234!
        echo $_GET['name'].','.$_GET['pwd'];
        ?>
        cs
      • 화면 출력 결과
        11111
        11111,12345
  • Form 입출력 : HTTP Method Type
    1. GET 
      • 특징 : url 상에 전송하는 데이터가 노출. 
      • 입력
        • URL  : http://127.0.0.1:8080/io_form/form_get.html
        • 파일명 : form_get.html
        • 소스코드
          1
          2
          3
          4
          5
          6
          7
          8
          9
          <html>
              <body>
                  <form method="get" action="output_get.php">
                      id : <input type="text" name="name"/>
                      password : <input type="text" name="pwd"/>
                      <input type="submit"/>    
                  </form>
              </body>
          </html>
          cs
      • 출력
        • URL : http://127.0.0.1:8080/io_form/output_get.php?name=11111&pwd=12345
        • 파일명 : output_get.php
        • 소스코드
          1
          2
          3
          4
          5
          6
          7
          8
          <?php
          // http://127.0.0.1:8080/io_form/input_output.php?name=12345
          // id 파라미터를 url로서 입력받아 화면에 출력해주는 내용.
          echo $_GET['name'];
          echo '<br/>';
          // http://127.0.0.1:8080/io_form/input_output.php?name=12345&pwd=1234!
          echo $_GET['name'].','.$_GET['pwd'];
          ?>
          cs
    2. POST
      • 특징 :
        • url 상에 데이터를 노출하지 않아도 데이터 전송. 
      • 입력
        • URL : http://127.0.0.1:8080/io_form/form_post.html
        • 파일명 : form_post.html
        • 소스코드
          1
          2
          3
          4
          5
          6
          7
          8
          9
          <html>
              <body>
                  <form method="post" action="output_post.php">
                      id : <input type="text" name="name"/>
                      password : <input type="text" name="pwd"/>
                      <input type="submit"/>    
                  </form>
              </body>
          </html>
          cs
      • 출력
        • URL : http://127.0.0.1:8080/io_form/output_post.php
        • 파일명 : output_post.php
        • 소스코드
          1
          2
          3
          <?php 
              echo $_POST['name'].','.$_POST['pwd'];
          ?>
          cs