팝업창에 POST값 전달하기
아직도 보안이라는 이유로 GET을 못쓰게 하고 POST를 사용하게 하는 곳이 있나보다. 보안상 POST와 GET은 큰 차이가 없다. 특히나 전송되는 데이터가 보안상 중요한 정보가 아니라 페이지 표현을 위해서 필요한 정보 정도라면 POST를 사용하는데서 얻어지는 보안상 이점은 없다. 그래도 굳이 하겠다면 아래처럼 할 수는 있다.
wah.or.kr 게시판(웹 방화벽)이 너무 후져서 소스 코드나 링크를 도저히 올릴 수가 없다. 작성한 글 버리기 아까워서 여기에 올린다.
index.php
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Sending post data to popup window</title>
</head>
<body>
<form action="popup.php" method="post" target="popup" onsubmit="window.open('popup.php', 'popup', 'width=100, height=100');">
<input type="hidden" name="var" value="POST DATA SENT">
<input type="submit">
</form>
</body>
</html>
popup.php
<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <title>Receiver popup</title> </head> <body> <p><?php echo($_POST['var']); ?></p> </body> </html>