Skip to content

Instantly share code, notes, and snippets.

@charlycoste
Created February 28, 2018 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlycoste/503dfc829b6eca238edbe13db8b95b16 to your computer and use it in GitHub Desktop.
Save charlycoste/503dfc829b6eca238edbe13db8b95b16 to your computer and use it in GitHub Desktop.
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
Copy link
Author

/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