File Server 1 (nhận dữ liệu - domain = http://localhost . com/file_nhan.php)
<?php
if(isset($_POST['du_lieu'])) {
// Lưu log khi nhận dữ liệu
$f = fopen('log.txt', 'a');
fwrite($f, $_POST['du_lieu']."\n");
fclose($f);
echo "Đã nhận biến du_lieu nội dung là: ".$_POST['du_lieu'];
}else {
echo 'nothing to show';
}
?>
File Server 2 (nhận dữ liệu)
<?php
$server_nhan = "http://localhost . com/file_nhan.php";
$data = array(
"du_lieu" => "hentaiz.net",
"du_lieu_test" => "nothing"
);
// khởi tạo curl
$ch = curl_init();
// khai báo url cho phiên curl
curl_setopt($ch, CURLOPT_URL, $server_nhan);
// khai báo sử dụng method post
curl_setopt($ch, CURLOPT_POST, 1);
// khai báo dữ liệu được gửi đi qua method post
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
// nhận lại dữ liệu show ra từ server nhận
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// gán biến cho dữ liệu nhận được từ phiên curl
$server_output = curl_exec($ch);
// đóng phiên curl
curl_close ($ch);
echo $server_output;
?>