.
This commit is contained in:
parent
5bcfce5caa
commit
17c99c1e4c
1 changed files with 58 additions and 0 deletions
58
php/pasta.php
Normal file
58
php/pasta.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
if(isset($_POST['link'])) {
|
||||
$link = $_POST['link'];
|
||||
|
||||
//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){
|
||||
$response = $errno . " " . $errstr;
|
||||
}
|
||||
else {
|
||||
//create the request headers
|
||||
$headers = array();
|
||||
$headers[] = 'HEAD ' . $request . ' HTTP/1.1';
|
||||
$headers[] = 'Host: ' . $host;
|
||||
$headers[] = 'Content-Length: 0';
|
||||
$headers[] = 'Connection: close';
|
||||
$headers[] = 'Content-Type: text/html';
|
||||
$headers = implode("\r\n", $headers) . "\r\n\r\n";
|
||||
|
||||
//send our request
|
||||
if (!fwrite($fp, $headers)) {
|
||||
fclose($fp);
|
||||
$response = "Could not access webpage specified.";
|
||||
}
|
||||
else {
|
||||
//read the response
|
||||
$rsp = '';
|
||||
while(!feof($fp)) { $rsp .= fgets($fp,8192); }
|
||||
fclose($fp);
|
||||
$hunks = explode("\r\n\r\n",trim($rsp));
|
||||
$headers = explode("\n", $hunks[count($hunks) - 1]);
|
||||
$response = trim($headers[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test Link</title>
|
||||
</head>
|
||||
<body>
|
||||
<?php if(isset($response)) { echo $response; } ?>
|
||||
<form method="post">
|
||||
<label for="link">Link</label>
|
||||
<input id="link" type="text" name="link" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue