2010-10-14 60 views
0

我已经在网络上查找了大概一个常见而简单的任务,并且只发现了死角。我试图从自己的HTML页面获取响应,该页面使用POST将数据提交到网站,以便我可以解析它并在同一个html页面上显示/打印解析后的文本。 这里是我的html页面看起来像什么:从窗体POST获取响应POST

<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> 
+2

开始将'form'元素移动到'body'元素中。它不应该在你的文档的头部。 – 2010-10-14 13:15:39

+0

基本示例:http://www.w3schools.com/php/php_forms.asp – Shoban 2010-10-14 13:15:42

+1

**危险**:来自W3Schools的“基本”示例存在XSS安全漏洞。避免W3Schools,因为这是典型的。 – Quentin 2010-10-14 13:26:41

回答

0

只是做<?php echo $_POST['username']; ?>

0

使用预定义变量$ _ 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> 
0

建议您在http://www.php.net/form阅读,因为它包含两个例子和良好注释。当你调用字段的用户名和密码时,我猜你可能也在查看数据库连接,要非常小心SQL注入(http://php.net/manual/en/security.database.sql-injection.php)。