Php 如何将帖子转换为url?
是否可以只使用url发送数据,即您必须使用提交按钮发送数据 下面是一个带有按钮的站点代码示例:Php 如何将帖子转换为url?,php,post,input,http-post,Php,Post,Input,Http Post,是否可以只使用url发送数据,即您必须使用提交按钮发送数据 下面是一个带有按钮的站点代码示例: <form method="POST" action="Action.php?action=338&n=688&t=mine"><input type="hidden" id="Mine688" value="1" name="duree"><button value="submit" class="boutonsGeneral" type
<form method="POST" action="Action.php?action=338&n=688&t=mine"><input type="hidden" id="Mine688" value="1" name="duree"><button value="submit" class="boutonsGeneral" type="submit" name="travail"><span title="" class="infoBoutonsGeneral"><span class="boutonsGeneral_separateur"> </span><span class="boutonsGeneral_gain" id="gainMine688"><img width="48" height="24" src="images/items/itemArgent.png">+2,18</span></span>Munca <span class="boutonsGeneral_duree boutonsGeneral_dureeMoins" id="dureeMine688">1 hour</span></button></form>
我想做的是通过url发送帖子。比如:
(直到这里是来自站点的链接,我想添加此链接)duree=1&travail=submit
不起作用,因此我想知道是否有可能做到这一点。使表单方法获取并将变量放入表单中的隐藏字段中。 例如:
<form method="GET" action="Action.php">
<input type="hidden" name="action" value="338" />
<input type="hidden" name="n" value="688" />
<input type="hidden" name="t" value="mime" />
...more html/php...
</form>
…更多html/php。。。
简短的回答是否定的
根据定义,GET变量在URL中发送,
和POST变量在请求主体中发送
因此,您不能按照您的要求仅通过使用URL发送变量
即使在POST请求中,您也可以通过参数捕获可能的URL,但我强烈建议您不要采用这种方法
你可以在post中了解更多信息。首先,你需要知道post和GET的用途
- 如果您想发送数据,您应该使用POST
- 如果要根据某些参数获取数据,请使用GET
使用GET发送数据没有任何意义,这也有一些限制。您可以阅读有关限制的更多信息
您始终可以使用CURL将POST数据发送到其他URL
下面是基于本教程的示例:
<?php
$url = 'http://www.kraljevine.com/Action.php?action=338&n=688&t=mine';
$fields = array(
'duree' => urlencode('1'),
'travail' => urlencode('submit')
);
//$fields can be extended with more params for POST submit always encode them with urlencode for these 2 examples of 1 submit it is not necessary but sometimes is really imporant to do it
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
?>
最后一件事是$\u REQUEST
,它是一个关联数组,默认情况下包含$\u GET、$\u POST和$\u COOKIE的内容。您可以在php脚本中使用它,并且在php脚本中传递变量的方式不会有任何区别
明智地使用它。您可以使用cURL发送post-parameters。使用方法GET-man。这要简单得多。使用get,您可以在url中显示变量。无缘无故地使事情复杂化。如果参数进入QUERYSTRING,则使用GET;如果参数进入表单,则使用POST。这很简单,在php代码中两个away的访问方式相同。
<?php
$url = 'http://www.kraljevine.com/Action.php?action=338&n=688&t=mine';
$fields = array(
'duree' => urlencode('1'),
'travail' => urlencode('submit')
);
//$fields can be extended with more params for POST submit always encode them with urlencode for these 2 examples of 1 submit it is not necessary but sometimes is really imporant to do it
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
?>