3v4l.org

run code in 300+ PHP versions simultaneously
<?php class header { private $secretKey = '123'; private $storeId = 10; public function __construct($content, $url) { $this->setContentMd5($content); $this->setHttpVerb($url); } private function setContentMd5($content) { $this->contentMd5 = md5($content); } private function setHttpVerb($url) { if (parse_url($url, PHP_URL_QUERY)) { $this->httpVerb = parse_url($url, PHP_URL_PATH).'?'.parse_url($url, PHP_URL_QUERY); } else { $this->httpVerb = parse_url($url, PHP_URL_PATH); } } private function generateAuthorization() { return hash_hmac( 'sha256', $this->httpVerb . $this->contentMd5, $this->secretKey ); } public function generateHeader() { $headers = array( 'Accept' => 'application/vnd.boacompra.com.v1+json; charset=UTF-8', 'Content-Type' => 'application/json', 'Content-MD5' => $this->contentMd5, 'Authorization' => $this->storeId . ':' . $this->generateAuthorization() ); return $headers; } } echo 'POST EXAMPLE <br /> <pre>'; $content = '{"payment-method":{"reference":"ID-CND9","direct-token":"eyJkbmEiOiJjMWRkMzliYTY4YjY0MjlkOTRmNTQzM2YwMTFiNTRlZiIsImlwIjoiMTcyLjIxLjExMi4xNjEiLCJkZiI6IjJmOTExZjdkOTgyZDQzMDY4YTNmYjc2MWRlZWQzZjI1In0=","notify-url":"https://virtual-store.com/notifications/","test-mode": 0,"payment-group":"credit_card","country":"BR","language":"pt-BR"},"payer":{"name":"João Pagão","email":"payer@uolinc.com","phone-area-code":"11","phone-number":"988881234","document":{"type":"CPF","number":"00000000191"},"birth-date":"1982-12-20"}}'; $headerPost = new header($content, 'https://api.boacompra.com/payment-methods'); print_r($headerPost->generateHeader());
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
POST EXAMPLE <br /> <pre> Deprecated: Creation of dynamic property header::$contentMd5 is deprecated in /in/4tkob on line 15 Deprecated: Creation of dynamic property header::$httpVerb is deprecated in /in/4tkob on line 23 Array ( [Accept] => application/vnd.boacompra.com.v1+json; charset=UTF-8 [Content-Type] => application/json [Content-MD5] => e11d2cda570ce29954f79c244334fd19 [Authorization] => 10:fd3859f2835ab75a2409831d42684fb74a9dd0011a05dbec3b934892a51ae265 )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 POST EXAMPLE <br /> <pre> Deprecated: Creation of dynamic property header::$contentMd5 is deprecated in /in/4tkob on line 15 Deprecated: Creation of dynamic property header::$httpVerb is deprecated in /in/4tkob on line 23 Array ( [Accept] => application/vnd.boacompra.com.v1+json; charset=UTF-8 [Content-Type] => application/json [Content-MD5] => e11d2cda570ce29954f79c244334fd19 [Authorization] => 10:fd3859f2835ab75a2409831d42684fb74a9dd0011a05dbec3b934892a51ae265 )
Output for 7.0.0 - 7.0.31, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
POST EXAMPLE <br /> <pre>Array ( [Accept] => application/vnd.boacompra.com.v1+json; charset=UTF-8 [Content-Type] => application/json [Content-MD5] => e11d2cda570ce29954f79c244334fd19 [Authorization] => 10:fd3859f2835ab75a2409831d42684fb74a9dd0011a05dbec3b934892a51ae265 )

preferences:
158.48 ms | 403 KiB | 211 Q