我只是想了解这是如何工作的…所以希望这不是一个愚蠢的问题。
但是让我们说我有一个html/PHP表单在我的网站,其中post数据到第三方系统…第三方需要做些什么才能收到我的数据?
假设我的表单是这样的:
<form id="userdata" method="post" action="https://thirdparty.com/receive_data.php">
<label>Name</label>
<input type="text" name="user_name">
<label>Email</label>
<input type="text" name="user_email">
<label>Phone</label>
<input type="text" name="user_phone">
<label>Message</label>
<textarea rows="20" cols="50" name="user_message"></textarea>
<input type="submit">
</form>
在本例中,我将数据发布到https://thirdparty.com/receive_data.php所以我假设第三方在receive_data.php中有代码,它告诉系统如何抓取我的数据并将其发送到他们的数据库。是否第三方的代码看起来类似于代码我将使用当我试图将我自己的表单的数据存储到我自己的数据库?他们是否使用额外的代码来允许第三方数据进入他们的数据库。有人可以解释这个给我,也许给我一个代码示例,这样我可以更好地理解这个
我还建议您使用CURL。
Curl扩展有很多可以设置的选项,例如连接超时。您还可以添加post变量或使用特定的引用访问该站点。它也给出响应发送url/服务器工作正常与否。
有n个功能,你可以在下面的链接中看到:https://curl.haxx.se/docs/comparison-table.html
你需要知道的关于它(和大多数其他扩展)的一切都可以在PHP手册中找到。
我建议使用cURL发送一些数据到其他站点。
$url = "https://thirdparty.com/receive_data.php";
$data = $_POST; // or something else, it depends on you what should be send
$ch = curl_init ($url );
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data );
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch); //Third part response, for example in JSON format