Created
February 28, 2018 17:50
-
-
Save charlycoste/503dfc829b6eca238edbe13db8b95b16 to your computer and use it in GitHub Desktop.
Quick and dirty link checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha256-3edrmyuQ0w65f8gfBsqowzjJe2iM6n0nKciPUp8y+7E=" crossorigin="anonymous"></script> | |
<script> | |
$(function(){ | |
$('body').html($('#tpl-form').html()); | |
}); | |
$(document).on('submit', function(e){ | |
e.preventDefault(); | |
$.each($('textarea').val().split("\n"), function(index, item){ | |
item = item.trim(); | |
$.get('/linkcheck/proxy.php?q='+item) | |
.done(function(){ | |
$('body').append('<li>'+item+' OK</li>'); | |
}) | |
.fail(function(){ | |
$('body').append('<li>'+item+' Failed</li>'); | |
}); | |
}); | |
$('body').empty(); | |
}); | |
</script> | |
</head> | |
<body> | |
<script id="tpl-form" type="plain/x-template"> | |
<form> | |
<textarea cols="80" rows="20"></textarea> | |
<div><button>Check</button></div> | |
</form> | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = filter_var($_GET['q'], FILTER_VALIDATE_URL); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_HEADER, true); // we want headers | |
curl_setopt($ch, CURLOPT_NOBODY, true); // we don't need body | |
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); | |
if ($httpcode >= 400 || empty($output)) { | |
header("HTTP/1.0 502 Bad Gateway"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/linkcheck/proxy.php
dans index.html est à modifier en fonction du chemin finalement utilisé pour proxy.php