3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php const URL_ROOT = 'http://www.jd.com'; $host = parse_url(URL_ROOT, PHP_URL_HOST) or die('Invalid URL_ROOT'); $url = URL_ROOT . $_SERVER['REQUEST_URI']; // Request URL $ch = curl_init($url) or die('curl_init failed.'); // Request Method curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD']); // Request Headers $headers = getallheaders(); $headers['Host'] = $host; $ch_headers = array(); foreach ($headers as $name => $value) $ch_headers[] = "$name: $value"; curl_setopt($ch, CURLOPT_HTTPHEADER, $ch_headers); // Request Body curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents("php://input")); // Send curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch) or die('curl_exec failed.'); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close($ch); // Response Header $header = substr($response, 0, $header_size); $headers = explode("\r\n", $header); foreach ($headers as $header) header($header); // Response Body $body = substr($response, $header_size); echo $body;
Output for 7.0.0 - 7.1.0
Notice: Undefined index: REQUEST_URI in /in/ZS3FN on line 5 Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/ZS3FN:8 Stack trace: #0 {main} thrown in /in/ZS3FN on line 8
Process exited with code 255.
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined index: REQUEST_URI in /in/ZS3FN on line 5 Notice: Undefined index: REQUEST_METHOD in /in/ZS3FN on line 11 Fatal error: Call to undefined function getallheaders() in /in/ZS3FN on line 14
Process exited with code 255.
Output for 5.3.0 - 5.6.28
Notice: Undefined index: REQUEST_URI in /in/ZS3FN on line 5 Fatal error: Call to undefined function curl_init() in /in/ZS3FN on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_CONST in /in/ZS3FN on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_CONST in /in/ZS3FN on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/ZS3FN on line 2
Process exited with code 255.