Title: PHP Example
Last modified: December 30, 2016

---

# PHP Example

 *  [lordmazus](https://wordpress.org/support/users/lordmazus/)
 * (@lordmazus)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/php-example/)
 * Hello, I have simple PHP rest api code (OAuth 1.0a) and I want to switch to JWT.
 *     ```
       <?php
       error_reporting(E_ALL & ~E_NOTICE); ini_set('display_errors', '1');
       if(isset($_POST['submit']))
           {
   
               // Token
               $authToken = 'OAuth oauth_consumer_key="XXXXXXX",oauth_token="XXXXXXXXX",oauth_signature_method="HMAC-SHA1",oauth_timestamp="XXXXXXXX",oauth_nonce="XXXXXX",oauth_version="1.0",oauth_signature="XXXXXXXXXX"';
   
               // The data to send to the API
               $postData = array('id' => $_POST["my_value"]);
   
               // Setup cURL
               $ch = curl_init('http://www.mysite.com/wp-json/wc/v1/customers/'.$postData['id'] );
               curl_setopt_array($ch, array(
                   CURLOPT_RETURNTRANSFER => TRUE,
                   CURLOPT_HTTPHEADER => array(
                       'Authorization: '.$authToken,
                       'Content-Type: application/x-www-form-urlencoded'
                   ),
                   //CURLOPT_POSTFIELDS => json_encode($postData)
               ));
   
               // Send the request
               $response = curl_exec($ch);
               var_dump($response);
   
               // Check for errors
               if($response === FALSE){
                   die(curl_error($ch));
               }
   
               // Decode the response
               $responseData = json_decode($response, TRUE);
               $responseData = json_decode($response);
               // Print the date from the response
               echo "</br>";
               echo $responseData->id;
               echo $responseData->billing->first_name;
   
           }
       ?>
       ```
   

The topic ‘PHP Example’ is closed to new replies.

 * ![](https://ps.w.org/jwt-authentication-for-wp-rest-api/assets/icon-256x256.jpg?
   rev=3372068)
 * [JWT Authentication for WP REST API](https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/jwt-authentication-for-wp-rest-api/)
 * [Active Topics](https://wordpress.org/support/plugin/jwt-authentication-for-wp-rest-api/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/jwt-authentication-for-wp-rest-api/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/jwt-authentication-for-wp-rest-api/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [lordmazus](https://wordpress.org/support/users/lordmazus/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/php-example/)
 * Status: not resolved