Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick and dirty link checker
<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>
<?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");
}
@charlycoste

This comment has been minimized.

Copy link
Owner Author

@charlycoste charlycoste commented Feb 28, 2018

/linkcheck/proxy.php dans index.html est à modifier en fonction du chemin finalement utilisé pour proxy.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment