2020-06-08 13:00:19 +00:00
|
|
|
<?php
|
2020-06-10 12:32:20 +00:00
|
|
|
if(isset($_GET['link'])) {
|
|
|
|
$link = $_GET['link'];
|
2020-06-08 13:00:19 +00:00
|
|
|
|
|
|
|
//remove protocol, we're assuming its http
|
|
|
|
if(strstr($link, '://') != false){
|
|
|
|
$link = substr($link, strpos($link,'://') + strlen('://'));
|
|
|
|
}
|
|
|
|
|
|
|
|
//split the url into host (www.example.com) and requested page (index.php) on the first slash
|
|
|
|
$host = substr($link, 0, strpos($link, '/'));
|
|
|
|
$request = substr($link, strpos($link, '/'));
|
|
|
|
|
|
|
|
//open a socket connection to the site on port 80 (http protocol port)
|
|
|
|
$fp = @fsockopen($host, 80, $errno, $errstr);
|
|
|
|
|
|
|
|
if($fp == false){
|
2020-06-10 12:32:20 +00:00
|
|
|
$response= "Hallo";
|
2020-06-08 13:00:19 +00:00
|
|
|
$response = $errno . " " . $errstr;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//create the request headers
|
|
|
|
$headers = array();
|
|
|
|
$headers[] = 'HEAD ' . $request . ' HTTP/1.1';
|
|
|
|
$headers[] = 'Host: ' . $host;
|
2020-06-10 12:32:20 +00:00
|
|
|
//$headers[] = 'Content-Length: 0';
|
2020-06-08 13:00:19 +00:00
|
|
|
$headers[] = 'Connection: close';
|
2020-06-10 12:32:20 +00:00
|
|
|
$headers[] = 'Content-Type: application/json; charset=utf-8';
|
2020-06-08 13:00:19 +00:00
|
|
|
$headers = implode("\r\n", $headers) . "\r\n\r\n";
|
|
|
|
|
|
|
|
//send our request
|
|
|
|
if (!fwrite($fp, $headers)) {
|
|
|
|
fclose($fp);
|
2020-06-10 12:32:20 +00:00
|
|
|
$response = "Hallo.";
|
2020-06-08 13:00:19 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
//read the response
|
|
|
|
$rsp = '';
|
|
|
|
while(!feof($fp)) { $rsp .= fgets($fp,8192); }
|
2020-06-10 13:24:05 +00:00
|
|
|
fclose($fp);
|
2020-06-10 12:32:20 +00:00
|
|
|
/*
|
2020-06-08 13:00:19 +00:00
|
|
|
$hunks = explode("\r\n\r\n",trim($rsp));
|
|
|
|
$headers = explode("\n", $hunks[count($hunks) - 1]);
|
2020-06-10 12:32:20 +00:00
|
|
|
$response = trim($headers[0]);*/
|
|
|
|
$response= $rsp;
|
2020-06-08 13:00:19 +00:00
|
|
|
}
|
2020-06-10 13:24:05 +00:00
|
|
|
|
2020-06-08 13:00:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test Link</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<?php if(isset($response)) { echo $response; } ?>
|
2020-06-10 12:32:20 +00:00
|
|
|
<form method="get">
|
2020-06-08 13:00:19 +00:00
|
|
|
<label for="link">Link</label>
|
|
|
|
<input id="link" type="text" name="link" />
|
|
|
|
</form>
|
|
|
|
</body>
|
|
|
|
</html>
|