For security reasons I have to forward a JSON Object from a Jquery Script to a PHP Script. Here is what I have done yet:
<?php
header('Access-Control-Allow-Origin: *');
$input = @file_get_contents('php://input');
$content = json_encode( $input );
$url = $_GET["trakt_url"]."KEY";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json')
);
$result = curl_exec($ch);
echo $result;
?>
If I log the $content I get the JSON Object but the page($url) at where I post to is getting an empty Object. Does someone have an idea what I am doing wrong?
Solved (someone answered correctly but the answer is deleted?!)
curl_setopt($ch, CURLOPT_POSTFIELDS, "json=$content");