title: PHP - HMAC Authentication
body: <p>I'm getting that error code (I'm using a public API so it's certainly working on their side ;)):</p>
  
  <blockquote>
    <p>HMAC authentication key and signature was given, but they are invalid.</p>
  </blockquote>
  
  <pre><code>function get_myself($request){
      $public_key = "MY_PUBLIC_KEY";
      $secret = "MY_PRIVATE_KEY";
  
      $parameters = array(
          "client_id" =&gt; $public_key,
          "client_secret" =&gt; $secret
      );
      $data = http_build_query($parameters);
  
      $ch = curl_init("https://localbitcoins.com".$request);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($ch, CURLOPT_USERAGENT, "curl");
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
      $nonce = time();
      $sig = base64_encode ( hash_hmac("sha256", $nonce.$public_key.$request, $secret ) );
      $options = array(
          CURLOPT_RETURNTRANSFER =&gt; 1,
          CURLOPT_TIMEOUT =&gt; 30,
          CURLOPT_HTTPHEADER =&gt;   array(
              "Apiauth-Key:".$public_key,
              "Apiauth-Nonce:".$nonce,
              "Apiauth-Signature:".$sig
          ),
      );
      curl_setopt_array($ch, $options);
      $result = curl_exec($ch);
      curl_close($ch);
      return $result;
  }
  
  $getinfo = array();
  $getinfo = get_myself("/api/myself/");
  echo "&lt;pre&gt;"; print_r($getinfo); echo "&lt;/pre&gt;";
  </code></pre>