๊ฐœ๋ฐœ๊ด€๋ จ/PHP

[PHP] GET/POST ๊ฐ’ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•!

๐Ÿป๊ณฐ์ด๐Ÿป 2020. 11. 26.
728x90

์ธ์‚ฌ๋ง

 

์ด๋ฒˆ์‹œ๊ฐ„์—๋Š” ๊ฐœ๋ฐœํ•˜์‹œ๋Š”๋ถ„๋“ค์ด๋ผ๋ฉด ๊ฐ€์žฅ ๊ธฐ๋ณธ์œผ๋กœ ์•Œ๊ณ ๊ณ„์‹œ๋Š” GET๊ณผ POST ์ž…๋‹ˆ๋‹ค!!

 

GET๊ณผ POST ์˜ ์ฐจ์ด์ ์—๋Œ€ํ•ด์„œ ์„ค๋ช…๋“œ๋ฆฌ์ž๋ฉด

 

์•„ ์•Œ๊ณ ์žˆ๋‹ค๊ตฌ์—ฌ?? ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๋‹ค..

 

์šฐ์„  POST๊ฐ’ ๋ถ€ํ„ฐ ํ™•์ธ์„ ํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

 

์†Œ์Šค์ฝ”๋“œ

<!DOCTYPE html>
<html lang="kor">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>developmentbear</title>
</head>
	<body>
		<form method="post" action="/eazybear/test.php">
			์ด๋ฆ„:<input type="text" name="name" id="name"><br>
			๋‚˜์ด:<input type="text" name="age" id="age"><br>
			์„ฑ๋ณ„: ๋‚จ์ž<input type="radio" name="sex" value="๋‚จ์ž">์—ฌ์ž<input type="radio" name="sex" value="์—ฌ์ž"><br>
			์ฃผ์†Œ:<input type="text" name="address"><br>
			<input type="submit" value="์ „์†ก">
		</form>
	</body>
</html>

form์—์„œ method๋ฅผ post๊ฐ’์„ ์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 

๊ฐ„๋‹จํ•˜๊ฒŒ ์ •๋ณด์ž…๋ ฅ ์ฐฝ์ž…๋‹ˆ๋‹ค.

 

์ด๋ ‡๊ฒŒ ์ž…๋ ฅํ•ด์ฃผ์—ˆ๊ณ  php ํŒŒ์ผ๋„ ํ•œ๋ฒˆ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

<?php
	echo $_POST;
?>

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค.

 

์ง€๊ธˆ ๋„˜์–ด์˜ค๋Š” ๊ฐ’์€ ๋ฐฐ์—ด์ด๊ธฐ์— ๋ฐฐ์—ด์„ ํ’€์–ด์„œ ๋ณด์—ฌ์•ผํ•ฉ๋‹ˆ๋‹ค.

 

<?php
	print_r($_POST);
?>

 

์ „์†ก์„ ๋ˆŒ๋ €๋”๋‹ˆ ์ด๋ ‡๊ฒŒ ๋‚˜์˜ค๋„ค์š” ๋ณด๊ธฐ๊ฐ€ ์ด๋ž˜๋„ ํž˜๋“ค๋‹ค?

 

 

<?php
	echo "<pre>";
	print_r($_POST);
	echo "</pre>";
?>

์ถœ๋ ฅ ๊ฒฐ๊ณผ

์ด๋ ‡๊ฒŒ <pre>ํƒœ๊ทธ๋ฅผ ์จ์ฃผ์‹œ๋ฉด ๋””๋ฒ„๊น… ํ• ๋•Œ ํŽธํ•˜๊ฒ ์ฃ ??

 

์ด๊ฑฐ ๊ด€๋ จํ•ด์„œ ํ•จ์ˆ˜ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด๋†“์œผ๋ฉด ์—„์ฒญ ํŽธํ•˜๊ฒŒ ์“ธ์ˆ˜์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๊ฑฐ ๊ด€๋ จํ•ด์„œ๋Š” ๋‹ค์Œ์‹œ๊ฐ„์— ์–˜๊ธฐํ•˜๋„๋กํ•˜์ฃต

 

์ด๋ ‡๊ฒŒ POST๊ฐ’์„ ํ•˜๋‚˜๋งŒ ๊ฐ€์ ธ์˜ค๊ณ ์‹ถ๋‹ค? ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ•˜๋‚˜์š”?

 

<?php
	echo $_POST['name'];
?>

์ถœ๋ ฅ ๊ฒฐ๊ณผ => ๊ฐœ๋ฐœ์‰ฝ๊ฒŒํ•˜์ž๊ณฐ

 

์ด๋ ‡๊ฒŒ [] << ๋กœ ใ…key๊ฐ’ ๋„ฃ์–ด์„œ ๊ฐ€์ง€๊ณ  ์˜ค๋ฉด๋ฉ๋‹ˆ๋‹ค!

 

๋‹ค์Œ์€ GET๊ฐ’์œผ๋กœ ์•Œ์•„๋ณผ๊นŒ์š”??

 

<!DOCTYPE html>
<html lang="kor">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>developmentbear</title>
</head>
	<body>
		<form method="get" action="/jmw/test.php">
			์ด๋ฆ„:<input type="text" name="name" id="name"><br>
			๋‚˜์ด:<input type="text" name="age" id="age"><br>
			์„ฑ๋ณ„: ๋‚จ์ž<input type="radio" name="zex" value="๋‚จ์ž">์—ฌ์ž<input type="radio" name="zex" value="์—ฌ์ž"><br>
			์ฃผ์†Œ:<input type="text" name="address"><br>
			<input type="submit" value="์ „์†ก">
		</form>
	</body>
</html>

์•„๊นŒ๋Š” form ์— method ๋ถ€๋ถ„์ด POST์˜€๋‹ค๋ฉด ์ด์   GET์œผ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”!

 

์ „์†ก๋ˆ„๋ฅด์‹œ๋ฉด ์ฃผ์†Œ์ฐฝ์— ์ฐํž๊ฒ๋‹ˆ๋‹ค.

 

PHP์—์„œ๋Š” $_POST -> $_GET์œผ๋กœ ๋ณ€๊ฒฝํ•˜์‹œ๋ฉด๋ฉ๋‹ˆ๋‹ค.

 

<?php
	echo "<pre>";
	print_r($_GET);
	echo "</pre>";
?>

์ด๋ ‡๊ฒŒ ํ•ด์ฃผ์‹œ๋ฉด GET๊ฐ’๋„ POST๊ฐ’์ฒ˜๋Ÿผ ํ™•์ธ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์ด๋ ‡๊ฒŒ GET๊ฐ’๋„ ํ™•์ธ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

์ด์ƒ ํฌ์ŠคํŒ… ์—ฌ๊ธฐ์„œ ๋งˆ๋ฌด๋ฆฌํ• ๊ป˜์šฉ~~!!

 

GET ๊ฐ’ POST๊ฐ’ ์•Œ์•„์˜ค๋Š”๊ฑฐ ๋„ˆ๋ฌด์‰ฝ์ฃ ?? ใ…Žใ…Ž๋‹ค๋“ค ์ข‹์€ํ•˜๋ฃจ ๋ณด๋‚ด์„ธ์š”!

 

๊ถ๊ธˆํ•˜์‹ ๊ฑฐ๋Š” ๋Œ“๊ธ€๋กœ ๋‚จ๊ฒจ์ฃผ์„ธ์š”!

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€