답변
직접 액세스가 불가능하다
. This is because PHP operates on the server, and JavaScript is executed in the browser, resulting in independent execution environments.
GET Request for Form Values
The example provided using $_GET is designed to retrieve form values submitted through a GET request. This method won't work for JavaScript variables since they are not part of the HTML form.
Hidden Form Field
A workaround to access JavaScript variables in PHP is to store them in a hidden form field. 여기에는 양식을 제출하기 전에 숨겨진 필드의 값을 JavaScript 변수로 설정하는 것이 포함됩니다. 그런 다음 $ _get.
// JavaScript 변수를 설정합니다
var test = "테스터";
// 숨겨진 입력 요소를 찾고 값을 설정합니다.
document.getElementById ( "test"). value = test;
스크립트>