Php 将数据发送到第三方服务器,然后检索回数据
这在PHP中是否可行:Php 将数据发送到第三方服务器,然后检索回数据,php,Php,这在PHP中是否可行: 用户在我的网站上填写表格 表单将表单中的数据提交给网络上其他地方的第三方服务器,实际上是以某种方式将数据传递给第三方服务器 第三方服务器对数据做了一些处理,然后生成一个数值发送回我的PHP脚本 我的服务器/PHP脚本获取该数值/数据,以便再次在脚本中使用 它在PHP中可行吗?PHP是否有内置函数来执行上述任务?这样的事情需要大量的高级代码,还是相对容易做到 提前感谢您对此事的帮助是的,当您发送表单时,请使用POST方法将其发送到您想要的服务器。这看起来像: <for
提前感谢您对此事的帮助是的,当您发送表单时,请使用POST方法将其发送到您想要的服务器。这看起来像:
<form action="www.siteURL/pageToParseCode.php" method="post">
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br />
<input type="submit" value="Submit" />
</form>
在将处理数据的服务器上,您可以使用类似于的方法将其发回服务器,如果您不完全理解,请查看那里的链接,或者您可以使用php标头,并使用get方法设置要发送回url的数据,因此,用户收到的url将如下所示:
www.yoursite.com/index.php?variable1=value1&variable2=value2等等,然后这样解释:
if (isset($_GET['variable1'])) {
$var = $_GET['variable1'];
}
你可以用cURL
$urltopost = "http://somewebsite.com/script.php";
$datatopost = $_POST; //This will be posted to the website, copy what has been posted to your website
$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$returndata = curl_exec ($ch); //This is the output the server sends back
cURL或内置流函数。cURL可能会出现在您的安装中;流函数肯定是。这在旋度下是非常可能的。。。
$urltopost = "http://somewebsite.com/script.php";
$datatopost = $_POST; //This will be posted to the website, copy what has been posted to your website
$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$returndata = curl_exec ($ch); //This is the output the server sends back