通过PHP CURL发送POST数据不起作用

Using the code below, I'm unable to send any POST data. The page that is supposed to receive it, isn't receiving it for some reason..

$url = "http://www.somesite.com/curl_test_page.php";

$employee_id = 5;
$post_fields = "employee_id=" . $employee_id;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);     

$result = curl_exec($ch);

On the curl_test_page.php, the code is as follows:

$employee_id = $_POST['employee_id'];
echo $employee_id;

When I run the CURL script, it displays an empty page.

You are not printing any output. Try adding

<?php
echo $result;
?>
  1. You are not using curl_init
  2. Is recomended force the enctype with CURLOPT_HTTPHEADER
  3. I recomend you use http_build_query function

Example:

$url = "http://www.somesite.com/curl_test_page.php";

$employee_id = 5;

$post_fields = Array(
    employee_id => $employee_id
);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_fields));     

$result = curl_exec($ch);