Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从表单POST获取响应_Php_Html - Fatal编程技术网

Php 从表单POST获取响应

Php 从表单POST获取响应,php,html,Php,Html,我在网上到处寻找可能是一项普通而简单的任务,除了死角什么也没找到。我试图从我自己的html页面中获取一个响应,该页面使用POST向网站提交数据,这样我就可以对其进行解析,并在同一html页面上显示/打印解析后的文本。 以下是我的html页面的外观: <html><head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <form method="pos

我在网上到处寻找可能是一项普通而简单的任务,除了死角什么也没找到。我试图从我自己的html页面中获取一个响应,该页面使用POST向网站提交数据,这样我就可以对其进行解析,并在同一html页面上显示/打印解析后的文本。 以下是我的html页面的外观:

    <html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<form 
 method="post" 
 action="http://somesite.com" 
 enctype="multipart/form-data">
 <input type="hidden" name="function"  value="login">
 <input type="text"   name="username"  value="client">
 <input type="text"   name="password"  value="qwerty">
 <input type="file"   name="upload">
 <input type="text"   name="upload_to"   value="0">
 <input type="text"   name="upload_type" value="0">
 <input type="submit" value="Send">
</form>
</head><body></body></html>

只需使用预定义变量$\u POST即可

<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<form 
 method="post" 
 action="" 
 enctype="multipart/form-data">
 <input type="hidden" name="function"  value="login">
 <input type="text"   name="username"  value="client">
 <input type="text"   name="password"  value="qwerty">
 <input type="file"   name="upload">
 <input type="text"   name="upload_to"   value="0">
 <input type="text"   name="upload_type" value="0">
 <input type="submit" value="Send">
</form>
<?php if("Send" == $_POST['submit']){ var_dump($_POST); } ?>
</head><body></body></html>


建议您继续阅读,因为它包含示例和良好的注释。在调用字段username和password时,我想您可能也在查看数据库连接,请非常小心SQL注入(http://php.net/manual/en/security.database.sql-injection.php).

首先将
表单
元素移动到
主体
元素中。它不应该出现在文档的
标题中。基本示例:危险:W3Schools的“基本”示例存在XSS安全漏洞。避免去学校,因为这是典型的学校。