3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php define("EBO_DEVICE_API_BASE", "http://device.api.eboradio.com"); define("EBO_DEVICE_METHOD_ACCESS", "/v1/authentication/access"); define("EBO_DEVICE_METHOD_ACTIVATION", "/v1/connection/activation"); define("EBO_DEVICE_METHOD_CONFIG", "/v1/server/config"); $serial_number = "EBOA1511CN82AEEF"; $device_key = "059d061d"; function http_request($url, $headers, $method='GET', $body=NULL) { global $error_msg; $curl=curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); if ($method == 'POST') { curl_setopt($curl, CURLOPT_POST, 1); if($body != NULL) curl_setopt($curl, CURLOPT_POSTFIELDS, $body); } curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($curl, CURLOPT_TIMEOUT, 10); $res = json_decode(curl_exec($curl), TRUE); $info = curl_getinfo($curl); curl_close($curl); print("\nhttp_response:\n".json_encode($res)."\n"); if($res == NULL || $res['message'] != "OK"){ print("\ncurl error:\n".json_encode($info)); if($res != NULL) { print("\nserver response:\n".json_encode($res)); $error_msg = $res['message']; } return NULL; } else { $error_msg = NULL; return $res['data']; } } function token_get() { global $serial_number, $device_key, $access_token, $expiration; $time_stamp = time(); $sha1_key=sha1($serial_number.$device_key.$time_stamp); $sign_key=md5($sha1_key); $headers = array("DEVICE-SN: ".$serial_number, "SIGNATURE: ".$sign_key, "REQUEST-TIME:".$time_stamp); print("\nHeaders :".json_encode($headers)."\n"); print("\nsignature:".$sign_key."\n"); $data = http_request(EBO_DEVICE_API_BASE.EBO_DEVICE_METHOD_ACCESS, $headers); if($data != NULL) { $access_token = $data['accesstoken']; $expiration = $time_stamp+240; print("\ntoken:".$access_token."\n"); } else { print("\nFailed to get token!\n"); $access_token = NULL; $expiration = 0; } return $access_token; } function activation() { global $access_token; $headers = array("ACCESS-TOKEN:".$access_token); return http_request(EBO_DEVICE_API_BASE.EBO_DEVICE_METHOD_ACTIVATION, $headers, 'POST'); } if(token_get() != NULL) { $headers = array("ACCESS-TOKEN:".$access_token); $config_data = http_request(EBO_DEVICE_API_BASE.EBO_DEVICE_METHOD_CONFIG, $headers); if($config_data != NULL) { print("\nconfig_data: ".strtolower($serial_number)."\n".json_encode($config_data)."\n"); } else { if ($error_msg == "DEVICE_NOT_ACTIVATED") { if(is_null(activation())) print("\ndevice activation fail !\n"); else { $config_data = http_request(EBO_DEVICE_API_BASE.EBO_DEVICE_METHOD_CONFIG, $headers); if($config_data != NULL) print("\nconfig_data: ".strtolower($serial_number)."\n".json_encode($config_data)."\n"); else print("\nget config fail !\n"); } } } } else print("\nget token fail ! \n"); ?>
Output for 7.0.0 - 7.2.0
Headers :["DEVICE-SN: EBOA1511CN82AEEF","SIGNATURE: 9de5403a2153c5a02f4f71198d310c67","REQUEST-TIME:1452751436"] signature:9de5403a2153c5a02f4f71198d310c67 Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/he0dU:13 Stack trace: #0 /in/he0dU(57): http_request('http://device.a...', Array) #1 /in/he0dU(77): token_get() #2 {main} thrown in /in/he0dU on line 13
Process exited with code 255.
Output for 5.5.0 - 5.6.28
Headers :["DEVICE-SN: EBOA1511CN82AEEF","SIGNATURE: 9de5403a2153c5a02f4f71198d310c67","REQUEST-TIME:1452751436"] signature:9de5403a2153c5a02f4f71198d310c67 Fatal error: Call to undefined function curl_init() in /in/he0dU on line 13
Process exited with code 255.