我在 php 中使用 curl 将数据从本地服务器发布到虚拟主机服务器:
$post = array('test' => 'this is a test' );
$url = "https://my-app.000webhostapp.com";
$curlSesh = curl_init();
curl_setopt($curlSesh, CURLOPT_URL, $url);
curl_setopt($curlSesh, CURLOPT_POST, true);
curl_setopt($curlSesh, CURLOPT_POSTFIELDS, $post);
curl_setopt($curlSesh, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curlSesh);
curl_close($curlSesh);
echo "response: ";
echo $response;
if ($response == "validate post")echo ' post has been validated';
在我的 000webhost 服务器上,我接受使用文件放置内容在 $post 中发送的数组:
file_put_contents('incomingData.txt', $_POST["test"]. "\n", FILE_APPEND );
当然,这意味着任何人都可以使用数组键“test”向我的虚拟主机服务器发送一个发布请求,并将其放在我的incomingData.txt 文件中?这是非常不安全的。有没有办法让它只接受我的本地服务器数据,或者我可以以某种方式加密数据?谢谢。