3v4l.org

run code in 300+ PHP versions simultaneously
<?php // API access key from Google API's Console define( 'API_ACCESS_KEY', 'AIzaSyBNVpyGHobo0YbdyOejbL7ixMES9iwV6VA' ); $registrationIds = array("APA91bHgZ3qu3-VeJ0RC0J9EyB33qX5jB4pX1qEiZtdEiYSJoF8gYA67AeL0j4g7z6sNwLHg1kIQ__p5foZhWnXBybhcEZjp650DzUZXqQBf_fZnWc8xqVIMQMUrdHOtzYDX7DsyL7fyFFoUsF9pElZh8AYftELjlGbJqs-mGZSYg6zBVgXjhq0"); // prep the bundle $msg = array ( 'message' => 'Hello Prem here. Did you get this. message', 'title' => 'This is a title. title', 'subtitle' => 'This is a subtitle. subtitle', 'tickerText' => 'Ticker text here...Ticker text here...Ticker text here', 'vibrate' => 1, 'sound' => 1 ); $fields = array ( 'registration_ids' => $registrationIds, 'data' => $msg ); $headers = array ( 'Authorization: key=' . API_ACCESS_KEY//, //'Content-Type: application/json' ); // Submit those variables to the server $post_data = array( 'test' => 'foobar', 'okay' => 'yes', 'number' => 2 ); // Send a request to example.com $result = post_request('https://android.googleapis.com/gcm/send', $fields, $headers); //$ch = curl_init(); //curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' ); //curl_setopt( $ch,CURLOPT_POST, true ); //curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers ); //curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true ); //curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false ); //curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) ); //$result = curl_exec($ch ); //curl_close( $ch ); echo $result; function post_request($url, $data, $headers, $referer='') { // Convert the data array into URL Parameters like a=b&foo=bar etc. $data = http_build_query($data); // parse the given URL $url = parse_url($url); if ($url['scheme'] != 'http') { die('Error: Only HTTP request are supported !'); } // extract host and path: $host = $url['host']; $path = $url['path']; // open a socket connection on port 80 - timeout: 30 sec $fp = fsockopen($host, 80, $errno, $errstr, 30); if ($fp){ // send the request headers: fputs($fp, "POST $path HTTP/1.1\r\n"); fputs($fp, "Host: $host\r\n"); if ($referer != '') fputs($fp, "Referer: $referer\r\n"); fputs($fp, $headers); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: ". strlen($data) ."\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); $result = ''; while(!feof($fp)) { // receive the results of the request $result .= fgets($fp, 128); } } else { return array( 'status' => 'err', 'error' => "$errstr ($errno)" ); } // close the socket connection: fclose($fp); // split the result header from the content $result = explode("\r\n\r\n", $result, 2); $header = isset($result[0]) ? $result[0] : ''; $content = isset($result[1]) ? $result[1] : ''; // return as structured array: return array( 'status' => 'ok', 'header' => $header, 'content' => $content ); } ?>
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.21, 7.0.0 - 7.0.20, 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, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Error: Only HTTP request are supported !
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: http_build_query() in /in/gIsag on line 62
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: http_build_query() in /in/gIsag on line 62
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: http_build_query() in /in/gIsag on line 62

preferences:
200.18 ms | 401 KiB | 329 Q