$_REQUEST["url"]); switch($_REQUEST["action"]){ case("ping"): require 'ping.php'; if ( ping( sanitizeHost($_REQUEST["url"]), ipv6($_REQUEST["url"]) ) ){ $r["status"] = "Looks like it's up from here."; $r["resp_code"] = 2; } else { $r["status"] = "Seems down. :("; $r["resp_code"] = 0; } break; case("http"): require 'http.php'; if ( !ipv6($_REQUEST["url"]) && filter_var(sanitizeUrl($_REQUEST["url"]), FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === false ){ $r["status"] = "Host not valid"; $r["resp_code"] = 0; } else { $status = isUp($_REQUEST["url"], ipv6($_REQUEST["url"])); if ( $status == 2 ) { $r["status"] = "Looks like it's up from here."; $r["resp_code"] = 2; } else if ($status >= 400) { $r["status"] = "Site responded with a ".$status." code."; $r["resp_code"] = 1; } else { $r["status"] = "Seems down. :("; $r["resp_code"] = 0; } } break; default: header($_SERVER["SERVER_PROTOCOL"] . " 400 Bad Request"); header("X-Debug: Please define a valid action."); $r["status"] = "not valid"; $r["data"] = 0; break; } echo json_encode($r);