title: cURL post php to remote server yields an empty array
body: <p>I want to pass an array or a variable using cURL and post to a remote server and echo the contents of the array or value of the variable. Seems simple enough. I have been scouring the internets in search of a solution and I'm 90% sure the problem lies somewhere between my keyboard and my chair so I'm here to post code,which is a mess due to the troubleshooting code added but is still simple enough to figure out easily.</p>
  
  <p>I have tried searching cURL post to remote server, server receiving empty database, and various combinations of that info.</p>
  
  <p>To the code; this is what is on my server and sending to the remote server.</p>
  
  <pre><code>/*
   * Data which is to submitted to the remote URL
   *
   *$_POST['key'] = "foo";
   */
  
   $post_array = array("mahesh","chari");
  
   // I have tried both of these
  
   // $post_array = array('fname'=&gt;'mahesh','lname'=&gt;'chari');
  
   /*
   * Initialize cURL and connect to the remote URL
   * You will need to replace the URL with your own server's URL
   * or wherever you uploaded this script to.
   */
  
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, 'http://www.5thandpenn.com/Worms/curlpost_hanlder.php' );
  
   /*
   * Instruct cURL to do a regular HTTP POST
   */
  
   curl_setopt($ch, CURLOPT_POST, TRUE);
  
   /*
   * Specify the data which is to be posted
   */
  
   curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array);
  
   /*
    * Tell curl_exec to return the response output as a string
   */
  
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  
   /**
   * Execute the cURL session
   */
  
   $response = curl_exec($ch );
  
   /**
   * Close cURL session and file
   */
  
   curl_close($ch );
  
   echo $response; // is Welcome Maheshchari.
  </code></pre>
  
  <p>The response I get on my local server is:
  Welcome website string(6) "mahesh" string(5) "chari" string(0) "" string(0) "" NULL NULL</p>
  
  <p>So I can see that the correct data is being sent to the remote server and return transfer is catching it and replying.</p>
  
  <p>The code on the remote server is this:</p>
  
  <pre><code>$site='website ';
  
  $firstname = 'text';
  
  $firstname = isset($_POST['fname']) ? $_POST['fname'] : '';
  
  $lastname= isset($_POST['lname']) ? $_POST['lname'] : '';
  
  $array = array($_POST[0], $_POST[1]);
  
  // $firstname=$_POST[0];
  
  // $lastname=$_POST[1];
  
  echo "Welcome ";
  
  echo $firstname;
  
  echo $lastname;
  
  echo $site;
  
  print $firstname;
  
  var_dump($array[0]);
  
  var_dump($array[1]);
  
  var_dump($firstname);
  
  var_dump($lastname);
  
  var_dump($post_array);
  
  var_dump($post_array['fname']);
  
  echo htmlspecialchars($_POST["fname"]);
  </code></pre>
  
  <p>The response from the remote server is:
  Welcome website NULL NULL string(0) "" string(0) "" NULL NULL</p>
  
  <p>So here I can see that the remote server is not getting the variables because they are NULL or string(0)</p>
  
  <p>Remote server php version: 5.6.17 on Linux</p>
  
  <p>Php version on my local server is: 5.6.10 on MAMP</p>
  
  <p>I know that the proper info is being sent and it is being returned by return-transfer to my local server. </p>
  
  <p>I know that the remote server is not receiving the data at least not into the php script so I assume that the data is being stripped somewhere along the line. </p>
  
  <p>Why is the remote server receiving NULL and empty array but echo works fine on my local server and most importantly how can I fix this to work?</p>
  
  <p>The end goal is to imbed an echo call into an html page on my remote server and reflect what is being sent to the remote server from a local server.</p>
  
  <p>I have tried http https, www and no www in the URL. I have tried many different variations of the code that should work nut nothing does work.
  So the remote server is not allowing the data in but will allow the data to be returned back because the local host can echo the return-transfer and the data is there.</p>