且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

仅允许从表单而不是直接访问PHP脚本

更新时间:2023-12-03 08:05:52

如果表单是使用 POST 方法提交的( method ="post" >< form> ),您仍然可以仅在POST请求上执行脚本,只需在顶部添加以下代码即可:

If the form is submitted using POST method (with attribute method="post" in <form>), you can still execute your script only on POST requests, by adding this at the top:

 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
   exit;
 }