I've been trying to use cURL to send data to a local IP. This IP is waiting to receive incoming data.
For this, I used the following code:
if(isset($_GET['post'])) {
$data = array(
'type' => 'direct',
'packages' => []
);
$curl = curl_init('http://192.168.2.10:12800/api/install');
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if (curl_errno($curl)) {
$error_msg = curl_error($curl);
}
echo curl_exec($curl);
if (isset($error_msg)) {
echo $error_msg;
} else {
echo 'OK!';
}
}
On localhost it works, but on a live website it doesn't.
I was thinking maybe it's not possible for non-localhost to communicate with localhost environments, but I'm unsure.
Is it possible to make my script send data to a local IP?
EDIT: Afterthought, do I have to switch to JavaScript to get this working?