[PHP] get / post 전송 방식

2022. 5. 25. 12:19·Stack/PHP

1. get

보안에 취약해서 '조회'할 때 쓰임

http://localhost/php/form/number.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="number.php" method="get">
        <input type="number" name="num1" max="20" min="1">
        <input type="number" name="num2" max="20" min="1">
        <button type="submit">전송</button>
        <button type="reset">취소</button>
    </form>
</body>
</html>

 

number.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <?php
        $num1 = $_GET['num1'];
        $num2 = $_GET['num2'];
    ?>
    <p>
        <?php
            if($num1 == $num2) {
                echo "num1의 값은 {$num1}이고 num2의 값은 {$num2}이며 같습니다.";
            } elseif($num1 > $num2) {
                echo "num1의 값은 {$num1}이고 num2의 값은 {$num2}이며 num1이 더 큽니다.";
            } else {
                echo "num1의 값은 {$num1}이고 num2의 값은 {$num2}이며 num2가 더 큽니다.";
            }
        ?>
    </p>
</body>
</html>

 

 

 

2. post

글을 수정하거나 회원가입 할 경우 ...,

http://localhost/php/form/number.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="number.php" method="post">
        <input type="number" name="num1" max="20" min="1">
        <input type="number" name="num2" max="20" min="1">
        <button type="submit">전송</button>
        <button type="reset">취소</button>
    </form>
</body>
</html>

 

number.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <?php
        $num1 = $_POST['num1'];
        $num2 = $_POST['num2'];
        var_dump($_POST);
    ?>
    <p>
        <?php
            if($num1 == $num2) {
                echo "num1의 값은 {$num1}이고 num2의 값은 {$num2}이며 같습니다.";
            } elseif($num1 > $num2) {
                echo "num1의 값은 {$num1}이고 num2의 값은 {$num2}이며 num1이 더 큽니다.";
            } else {
                echo "num1의 값은 {$num1}이고 num2의 값은 {$num2}이며 num2가 더 큽니다.";
            }
        ?>
    </p>
</body>
</html>

 


 

 

HTML input태그의 name이 PHP 받아오는 변수 배열의 키 값으로 들어감 !

'Stack > PHP' 카테고리의 다른 글

[PHP] empty() / isset() / include  (0) 2022.05.26
[PHP] file  (0) 2022.05.25
[PHP] 제어문  (0) 2022.05.25
[PHP] 연산자 (증감 / 비교 / 논리 / 기타)  (0) 2022.05.25
[PHP] 배열  (0) 2022.05.25
'Stack/PHP' 카테고리의 다른 글
  • [PHP] empty() / isset() / include
  • [PHP] file
  • [PHP] 제어문
  • [PHP] 연산자 (증감 / 비교 / 논리 / 기타)
7ingout
7ingout
  • 7ingout
    Hello, 7ingout world!
    7ingout
  • 전체
    오늘
    어제
    • 분류 전체보기 (205)
      • Project (5)
      • Stack (173)
        • React (40)
        • JavaScript (50)
        • TypeScript (14)
        • HTML (11)
        • CSS (31)
        • Spring (9)
        • PHP (15)
        • SQL (3)
        • Python (0)
      • ETC (9)
      • Design (13)
        • Illustrator (6)
        • Photoshop (7)
      • Articloid (4)
        • 7ingout (4)
  • 공지사항

    • ☻
  • 인기 글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
7ingout
[PHP] get / post 전송 방식
상단으로

티스토리툴바