Skip to content

Instantly share code, notes, and snippets.

@jhammann
Last active March 8, 2018 12:37
Show Gist options
  • Save jhammann/7229987149869adca0e67e9443013985 to your computer and use it in GitHub Desktop.
Save jhammann/7229987149869adca0e67e9443013985 to your computer and use it in GitHub Desktop.
Detect the status of any webpage by sending an encoded URL as a query string. This returns a code as JSON.
<?php
header('Content-type: text/json');
header('Content-type: application/json');
$url = urldecode($_GET['url']);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$responseArray['status'] = $httpcode;
echo json_encode($responseArray);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment