3v4l.org

run code in 300+ PHP versions simultaneously
<?PHP error_reporting(); ini_set('display_errors', 'On'); function makeRequest($url, $requestBody) { $handle = curl_init(); $headers = array(); //array of request headers //Example headers for standart browser request //$headers = array( // 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'); curl_setopt($handle, CURLOPT_URL, $url); curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($handle, CURLOPT_POST, 1); curl_setopt($handle, CURLOPT_POSTFIELDS, $requestBody); curl_setopt($handle, CURLOPT_HTTPHEADER, $headers); curl_setopt($handle, CURLOPT_HEADER, 1); //This means include headers in response $result = curl_exec($handle); $header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE); $responseHeaders = substr($result, 0, $header_size); $responseBody = substr($result, $header_size, strlen($result) - $header_size); $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); if ($httpCode == 200) return $responseBody; else throw new Exception($responseBody); } $method = $_SERVER["REQUEST_METHOD"]; $request = array(); $request["a"] = "1"; $request["b"] = "3"; $request["c"] = "4"; $request["d"] = "7"; //$request = "a=1&b=3&c=4&d=7"; //This is the same with array version for standart post request. $response = makeRequest("http://httpbin.org/post", $request); echo $response; ?>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: Undefined array key "REQUEST_METHOD" in /in/IGveO on line 31 Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/IGveO:7 Stack trace: #0 /in/IGveO(40): makeRequest('http://httpbin....', Array) #1 {main} thrown in /in/IGveO on line 7
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined index: REQUEST_METHOD in /in/IGveO on line 31 Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/IGveO:7 Stack trace: #0 /in/IGveO(40): makeRequest('http://httpbin....', Array) #1 {main} thrown in /in/IGveO on line 7
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/IGveO:7 Stack trace: #0 /in/IGveO(40): makeRequest('http://httpbin....', Array) #1 {main} thrown in /in/IGveO on line 7
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Notice: Undefined index: REQUEST_METHOD in /in/IGveO on line 31 Fatal error: Call to undefined function curl_init() in /in/IGveO on line 7
Process exited with code 255.

preferences:
134.79 ms | 402 KiB | 183 Q