[英]How to pass the result of a form to another website with cURL?
我是网络开发领域的新手。请告诉我一些错误和知识不足。
当前正在研究PHP cUrl,因为根据我的朋友们以及根据我的研究,仍然不确定是否适合我当前项目的php库。
我正在创建一个表单,如果用户输入了一些内容,然后单击“提交”按钮,则表单中的结果将被传递到另一个网站,然后我将输出该结果。
从来没有使用cUrl的背景,而只是最近才了解其基本结构。 因此,我发布此消息是为了获得一些有关如何在项目中使用它的建议。 感谢所有帮助tnx。
我目前在下面学习的基本结构:
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://somesite.com');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer))
{
print "Yeah.<p>";
}
else
{
print $buffer;
}
?>
您需要使用这些cURL
参数
curl_setopt($curl_handle,CURLOPT_POST,1); //You have to enable the POST
curl_setopt($curl_handle,CURLOPT_POSTFIELDS,$yourformfields); //Your form fields will be sent here
$username=$_POST['username'];//values from your form
$password=$_POST['password'];
$yourformfields="username=$username&password=$password";
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://somesite.com');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle,CURLOPT_POST,1);
curl_setopt($curl_handle,CURLOPT_POSTFIELDS,$yourformfields);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer))
{
print "Yeah.<p>";
}
else
{
print $buffer;
}
?>
您也可以通过直接将表单操作设置为另一个网站上的url来尝试仅HTML的解决方案。 在这种情况下,不需要cURL或PHP。 如果method =“ post”不起作用,您可能还想尝试method =“ get”。
<form action="http://otherwebsite.com/formhandle.php" method="post">
...
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.