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":"cebolas"},"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/7nO7o on line 15 Deprecated: Creation of dynamic property header::$httpVerb is deprecated in /in/7nO7o on line 23 Array ( [Accept] => application/vnd.boacompra.com.v1+json; charset=UTF-8 [Content-Type] => application/json [Content-MD5] => 7724bd0c41ea36b6f5f9fe8457bb85fb [Authorization] => 10:cb7ab6555ad6d2cbe7f3c94a47f485ac69c10866dcbec6d8fc8d7c436b6a49ff )
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/7nO7o on line 15 Deprecated: Creation of dynamic property header::$httpVerb is deprecated in /in/7nO7o on line 23 Array ( [Accept] => application/vnd.boacompra.com.v1+json; charset=UTF-8 [Content-Type] => application/json [Content-MD5] => 7724bd0c41ea36b6f5f9fe8457bb85fb [Authorization] => 10:cb7ab6555ad6d2cbe7f3c94a47f485ac69c10866dcbec6d8fc8d7c436b6a49ff )
Output for 7.0.0 - 7.0.31, 7.1.0 - 7.1.21, 7.2.0 - 7.2.33, 7.3.16 - 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] => 7724bd0c41ea36b6f5f9fe8457bb85fb [Authorization] => 10:cb7ab6555ad6d2cbe7f3c94a47f485ac69c10866dcbec6d8fc8d7c436b6a49ff )

preferences:
150.36 ms | 403 KiB | 204 Q