{"id":500,"date":"2024-04-26T01:45:35","date_gmt":"2024-04-26T01:45:35","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=500"},"modified":"2024-04-27T09:29:05","modified_gmt":"2024-04-27T09:29:05","slug":"phpcheck-input-data-validity","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2024\/04\/26\/phpcheck-input-data-validity\/","title":{"rendered":"php\uc785\ub825\ub370\uc774\ud130 \uc720\ud6a8\uc131 \ud655\uc778\ud558\uae30Check input data validity"},"content":{"rendered":"\n<p>\ubcf4\ub77c\uc0c9 \ubd80\ubd84\uc740 form_action5-1.php\ud30c\uc77c\uc5d0\uc11c \uc720\ud6a8\uc131 \ud655\uc778\uc744 \uc704\ud574 form5-1.php\ud30c\uc77c\uc5d0\uc11c \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8 \ud3fc \uccb4\ud06c \ubd80\ubd84\uc744 \uc0ad\uc81c\ud569\ub2c8\ub2e4.<br>form_action5-1.php\ud30c\uc77c\uc5d0\uc11c \uac12\uc744 \uccb4\ud06c\ud558\ub294\ub370 \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8\ub85c \ud3fc\uccb4\ud06c \ud558\ub294 \ubd80\ubd84\uacfc \uc720\uc0ac\ud569\ub2c8\ub2e4.<br>\ub2e4\ub9cc \ud558\ub298\uc0c9 \ubd80\ubd84\uc740 php\uc5d0\uc11c \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8 \uc2e4\ud589 \ud558\ub294 \ubd80\ubd84\uc785\ub2c8\ub2e4.<br>alert()\ud568\uc218\ub85c \uba54\uc138\uc9c0\ub97c \ubcf4\ub0b4\uace0 \ud398\uc774\uc9c0 \uc774\ub3d9\uc744 \ud569\ub2c8\ub2e4. <br>window.location.href='[page]&#8217;; \ub300\uc2e0\uc5d0 history.go(-1);\uc744 \uc4f8 \uc218\ub3c4 \uc788\ub294\ub370 \uc798\ubabb\ub41c \uacf3\uc73c\ub85c \uc774\ub3d9\ud560 \uac00\ub2a5\uc131\uc774 \ud07d\ub2c8\ub2e4.<br>\uadf8\ub798\uc11c window.location.href='[page]&#8217;;\ub97c \uc0ac\uc6a9\ud558\ub294\uac8c \ub354 \ud6a8\uc728\uc801\uc785\ub2c8\ub2e4.<br><\/p>\n\n\n\n<p>The purple part deletes the JavaScript form check part from the form5-1.php file to confirm validity in the form_action5-1.php file.<br>Checking the value in the form_action5-1.php file is similar to checking the form using JavaScript.<br>However, the light blue part is the part where JavaScript is executed in PHP.<br>Send a message using the alert() function and move to the page.<br>window.location.href='[page]&#8217;; You could use history.go(-1); instead, but it would most likely take you to the wrong place.<br>So it is more efficient to use window.location.href='[page]&#8217;;<\/p>\n\n\n\n<p>\uc544\ub798\uc758 \ub9c1\ud06c\ub97c \ud1b5\ud574\uc11c \ud14c\uc2a4\ud2b8 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4<br>You can test it through the link below<br><a href=\"https:\/\/freelifemakers.org\/lec\/form5-1.php\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/freelifemakers.org\/lec\/form5-1.php<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>form5-1.php\n&lt;?php\n\n$fileName = \".\/form_action5-1.php\";\n\nif(!is_file($fileName)){\n    $form_action_name = basename($_SERVER&#91;'PHP_SELF']);\n}else{\n    $form_action_name = \".\/form_action5-1.php\";\n}\n?&gt;\n\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n    &lt;head&gt;\n      &lt;title&gt;Bootstrap 5 webform&lt;\/title&gt;\n      &lt;!--\uc774 \ubd80\ubd84\uc740 html\ucf54\uba58\ud2b8 \uc601\uc5ed This part is the html comment area,\ub9c8\uc784\ud0c0\uc785\uc124\uc815 Mime type settings\/\/--&gt;\n      &lt;meta charset=\"utf-8\"&gt;\n      &lt;!-- \ubaa8\ubc14\uc77c\ud3f0 \uc2a4\ud06c\ub9b0 \uc635\uc158 Mobile phone screen options\/\/--&gt;\n      &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"&gt;\n      &lt;!--\ubd80\ud2b8\uc2a4\ud2b8\ub7a95 CDN\ubc29\uc2dd \ub9c1\ud06c Bootstrap 5 CDN method link\/\/--&gt;\n      &lt;link href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.2.3\/dist\/css\/bootstrap.min.css\" rel=\"stylesheet\"&gt;\n      &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.2.3\/dist\/js\/bootstrap.bundle.min.js\"&gt;&lt;\/script&gt;\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#8c2dfa\" class=\"has-inline-color\">      &lt;script&gt;\n        function frmSubmit(){\n            frm.submit();\n        }\n      &lt;\/script&gt;<\/mark>\n    &lt;\/head&gt;\n    &lt;body&gt;  \n    &lt;div class=\"container-sm\"&gt;    \n        &lt;form id=\"frm\" action=\"&lt;?php echo $form_action_name; ?&gt;\" method=\"post\"&gt;\n        &lt;div class=\"mb-3\"&gt;\n            &lt;label for=\"name\" class=\"form-label\"&gt;\uc774\ub984(Name):&lt;\/label&gt;\n            &lt;input type=\"text\" class=\"form-control\" id=\"name\" placeholder=\"\ub2f9\uc2e0\uc758 \uc774\ub984\uc744 \uc785\ub825\ud558\uc138\uc694(Pleas enter your name)\" name=\"name\" required&gt;\n            &lt;div id=\"errorName\"&gt;&lt;\/div&gt;\n        &lt;\/div&gt;\n\n        &lt;div class=\"mb-3\"&gt;\n        &lt;label for=\"email\" class=\"form-label\"&gt;Email:&lt;\/label&gt;\n            &lt;input type=\"text\" class=\"form-control\" id=\"email\" placeholder=\"ID@exmale.com\" name=\"email\" required&gt;\n            &lt;div id=\"errorEmail\"&gt;&lt;\/div&gt;\n        &lt;\/div&gt;\n\n        &lt;div class=\"mb-3\"&gt;\n        &lt;label for=\"website\" class=\"form-label\"&gt;Website:&lt;\/label&gt;\n            &lt;input type=\"text\" class=\"form-control\" id=\"website\" placeholder=\"example.com\" name=\"website\"&gt;\n            &lt;div id=\"errorWebsite\"&gt;&lt;\/div&gt; \n        &lt;\/div&gt;\n        \n        &lt;div class=\"mb-3\"&gt;\n            &lt;label for=\"pwd\" class=\"form-label\"&gt;Title:&lt;\/label&gt;\n            &lt;input type=\"text\" class=\"form-control\" id=\"title\" placeholder=\"\uc81c\ubaa9\uc744 \uc785\ub825\ud558\uc138\uc694(Please enter the post title)\" name=\"title\" required&gt;\n            &lt;div id=\"errorTitle\"&gt;&lt;\/div&gt;\n        &lt;\/div&gt;\n\n        &lt;div class=\"mb-3\"&gt;\n            &lt;label for=\"pwd\" class=\"form-label\"&gt;Password:&lt;\/label&gt;\n            &lt;input type=\"password\" class=\"form-control\" id=\"pwd\" placeholder=\"Enter password\" name=\"pswd\" required&gt;\n            &lt;div id=\"errorPwd\"&gt;&lt;\/div&gt;\n        &lt;\/div&gt;        \n\n        &lt;div class=\"mb-3\"&gt;\n            &lt;label for=\"comment\" class=\"form-label\"&gt;Comment:&lt;\/label&gt;    \n            &lt;textarea id=\"comment\"name=\"comment\" rows=\"5\" cols=\"40\" class=\"form-control\"&gt;&lt;\/textarea&gt;\n            &lt;div id=\"errorComment\"&gt;&lt;\/div&gt;\n        &lt;\/div&gt;\n\n        &lt;div class=\"mb-3\"&gt;\n            &lt;div class=\"form-check mb-3\"&gt;\n            &lt;label class=\"form-check-label\"&gt;Remember me&lt;\/label&gt;\n            &lt;input class=\"form-check-input\" type=\"checkbox\" name=\"remember\"&gt;\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n            &lt;button type=\"button\" class=\"btn btn-primary\" onClick=\"frmSubmit();\"&gt;Submit&lt;\/button&gt;\n        &lt;\/form&gt;\n    &lt;\/div&gt;    \n    &lt;\/body&gt;\n&lt;\/html&gt;   <\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>form_action5-1.php\n&lt;?php  \n\nif($_SERVER&#91;'REQUEST_METHOD'] == \"POST\"){\n\n   $f_name = $_POST&#91;'name'];\n   $f_pwd = $_POST&#91;'pswd'];\n   $f_email = $_POST&#91;'email'];\n   $f_title = $_POST&#91;'title'];\n   $f_website = $_POST&#91;'website'];\n   $f_comment = $_POST&#91;'comment'];\n\n   \/\/ post data blank check\n   if($f_name == \"\"){\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#76a7f2\" class=\"has-inline-color\">    echo (\"&lt;script&gt;\n            alert('\uc774\ub984\uc744 \uc785\ub825\ud558\uc138\uc694(Please Enter Your Name).');\n            window.location.href = '.\/form5-1.php';\n           &lt;\/script&gt;\n        \");\n    exit; <\/mark>\n   }else if($f_email == \"\"){ \n    echo (\"&lt;script&gt;\n           alert('Email\uc744 \uc785\ub825\ud558\uc138\uc694(Please Enter Your Email).');\n           window.location.href = '.\/form5-1.php';\n           &lt;\/script&gt;\n        \");\n    exit;   \n   }else if($f_title == \"\"){ \n    echo (\"&lt;script&gt;\n           alert('\uae00 \uc81c\ubaa9\uc744 \uc785\ub825\ud558\uc138\uc694(Please Enter Your Post Title).');\n           window.location.href = '.\/form5-1.php';\n           &lt;\/script&gt;\n        \");\n    exit;                  \n   }else if($f_comment == \"\"){\n      echo (\"&lt;script&gt;\n              alert('\uae00\ub0b4\uc6a9\uc744 \uc785\ub825\ud558\uc138\uc694(Please Enter The post content).');\n              window.location.href = '.\/form5-1.php';\n             &lt;\/script&gt;\n          \");\n      exit;     \n   }else if($f_pwd == \"\"){\n    echo (\"&lt;script&gt;\n            alert('\ud328\uc2a4\uc6cc\ub4dc\ub97c \uc785\ub825\ud558\uc138\uc694(Please Enter Your Password).');\n            window.location.href = '.\/form5-1.php';\n           &lt;\/script&gt;\n        \");\n    exit;    \n   }   \n\n   \/\/ email check\n   if (!preg_match(\"\/^&#91;\\w-]+(\\.&#91;\\w-]+)*@(&#91;\\w-]+\\.)+&#91;a-zA-Z]{2,7}$\/\",$f_email)) {\n      echo (\"&lt;script&gt;\n            alert('\uc815\ud655\ud55c Email\uc744 \uc785\ub825\ud558\uc138\uc694(Please enter the correct Email).');\n            window.location.href = '.\/form5-1.php';\n            &lt;\/script&gt;\n         \");\n       exit;\n   }\n   \/\/ URL check\n    if (!preg_match(\"\/^(https?:\\\/\\\/)?(&#91;a-z0-9-]+\\.)+&#91;a-z]{2,7}(\\\/\\S*)?$\/i\",$f_website)) {\n   echo (\"&lt;script&gt;\n         alert('\uc815\ud655\ud55c URL\uc744 \uc785\ub825\ud558\uc138\uc694(Please enter the correct URL).');\n         window.location.href = '.\/form5-1.php';\n         &lt;\/script&gt;\n      \");\n    exit;\n   }\n\n\n}\n\n   echo \"REQUEST_METHOD:\".$_SERVER&#91;'REQUEST_METHOD'].\"&lt;br&gt;\";\n   echo \"\uc774\ub984(NAME):\".$f_name.\"&lt;br&gt;\";\n   echo \"\uc774\uba54\uc77c(EMAIL):\".$f_email.\"&lt;br&gt;\";\n   echo \"\uc81c\ubaa9(TITLE):\".$f_title.\"&lt;br&gt;\";\n   echo \"\uc6f9\uc0ac\uc774\ud2b8(WEBSITE):\".$f_website.\"&lt;br&gt;\";\n   echo \"\uae00 \ub0b4\uc6a9(CONTENT):\".$f_comment.\"&lt;br&gt;\";\n   echo \"\ud328\uc2a4\uc6cc\ub4dc(PASSWORD):\".$f_pwd;\n\n?&gt;<\/code><\/pre>\n\n\n\n<iframe loading=\"lazy\" src=\"https:\/\/www.facebook.com\/plugins\/video.php?height=314&#038;href=https%3A%2F%2Fwww.facebook.com%2Fgideonslife01%2Fvideos%2F1382424779130084%2F&#038;show_text=false&#038;width=560&#038;t=0\" width=\"560\" height=\"314\" style=\"border:none;overflow:hidden\" scrolling=\"no\" frameborder=\"0\" allowfullscreen=\"true\" allow=\"autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share\" allowFullScreen=\"true\"><\/iframe>\n","protected":false},"excerpt":{"rendered":"<p>\ubcf4\ub77c\uc0c9 \ubd80\ubd84\uc740 form_action5-1.php\ud30c\uc77c\uc5d0\uc11c \uc720\ud6a8\uc131 \ud655\uc778\uc744 \uc704\ud574 form5-1.php\ud30c\uc77c\uc5d0\uc11c \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8 \ud3fc \uccb4\ud06c \ubd80\ubd84\uc744 \uc0ad\uc81c\ud569\ub2c8\ub2e4.form_action5-1.php\ud30c\uc77c\uc5d0\uc11c \uac12\uc744 \uccb4\ud06c\ud558\ub294\ub370 \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8\ub85c \ud3fc\uccb4\ud06c \ud558\ub294 \ubd80\ubd84\uacfc \uc720\uc0ac\ud569\ub2c8\ub2e4.\ub2e4\ub9cc \ud558\ub298\uc0c9 \ubd80\ubd84\uc740 php\uc5d0\uc11c \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8 \uc2e4\ud589 \ud558\ub294 \ubd80\ubd84\uc785\ub2c8\ub2e4.alert()\ud568\uc218\ub85c \uba54\uc138\uc9c0\ub97c \ubcf4\ub0b4\uace0 \ud398\uc774\uc9c0 \uc774\ub3d9\uc744 \ud569\ub2c8\ub2e4. window.location.href='[page]&#8217;; \ub300\uc2e0\uc5d0 history.go(-1);\uc744 \uc4f8 \uc218\ub3c4 \uc788\ub294\ub370 \uc798\ubabb\ub41c \uacf3\uc73c\ub85c \uc774\ub3d9\ud560 \uac00\ub2a5\uc131\uc774 \ud07d\ub2c8\ub2e4.\uadf8\ub798\uc11c window.location.href='[page]&#8217;;\ub97c \uc0ac\uc6a9\ud558\ub294\uac8c \ub354 \ud6a8\uc728\uc801\uc785\ub2c8\ub2e4. The purple part deletes the JavaScript form check part [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-500","post","type-post","status-publish","format-standard","hentry","category-php","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=500"}],"version-history":[{"count":7,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/500\/revisions"}],"predecessor-version":[{"id":522,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/500\/revisions\/522"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}