title: Post JSON data to an API via PHP
body: <p>I need to integrate JSON into PHP, more specifically I need to post some information from a php page on our site to initiate an API request which will then send me information back. The information I am sending revolves around login information and I am struggling to work out how I can send this information. </p>
  
  <p>This is the information I need to post:</p>
  
  <pre><code>POST /user/?action=login HTTP/1.1
  Host: api.interlinkexpress.com
  Content-Type: application/json
  Accept: application/json
  Authorization: Basic RFNNSVRIOk1ZUEFTU1dE
  GEOClient: account/123456
  Content-Length: 0
  </code></pre>
  
  <p>Reading around the subject I have seen that php cURL may be useful however the example I have doesn't contain all the information I need to pass over. Also I am unsure on whether I need to pass it via a button as well:</p>
  
  <pre><code>      $data = array("username" =&gt; "TESTAPI", "password" =&gt; "APITEST");                                                                    
          $data_string = json_encode($data);                                                                                   
  
          $ch = curl_init('http://api.interlinkexpress.com');                                                                      
          curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
          curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
          curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
          'Content-Type: application/json',                                                                                
          'Content-Length: ' . strlen($data_string))                                                                       
          );                                                                                                                   
  
          $result = curl_exec($ch);
  </code></pre>
  
  <p>Any help on this matter would be appreciated. I am new to JSON having only learnt about it fleetingly.</p>
  
  <p>edit: I suppose the main thing I'm asking is how do I pass this information to the API in PHP?</p>
  
  <pre><code> POST /user/?action=login HTTP/1.1
   Host: api.interlinkexpress.com
   Content-Type: application/json
   Accept: application/json
   Authorization: Basic RFNNSVRIOk1ZUEFTU1dE (this is the login credentials)
   GEOClient: account/123456
   Content-Length: 0
  </code></pre>