|
|
|
| Title : |
ServerInfo - Remotely identify the software a web server is running. Create yourself a mini Netcraft :) |
| Categories : |
PHP, HTTP |
 Simon Booth |
| Date : |
Oct 12th 2000 |
| Grade : |
5 of 5 (graded 2 times) |
| Viewed : |
3925 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Simon Booth |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
<script language="php">
/***************************************************
* ServerInfo v 1.0 *
* *
* (c) Simon Booth 2000 *
* *
* These two functions return the information as *
* to what server and extensions a particular web *
* server is running. *
* *
* Both functions take the name/IP of a server and *
* an optional port to connect to. *
* *
* function GetServerList($host [, $port = 80]); *
* *
* Returns an array of server and extensions on *
* target host. *
* *
* function GetServerInfo($host [, $port = 80]); *
* *
* This function returns the 'Server: ' header *
* information, this is a line something like: *
* *
* *
***************************************************/
function GetServerList($host, $port = 80)
{
$server_list = false; //
Set return value to false initially
$idx = 0; //
Initialise index into $server_list
$server = trim(GetServerInfo($host, $port)); // Get
the 'Server: ' line from the host
if($server != "") // If we got
something back...
{
unset($server_list); // Unset
$server_list so we can use it as an array
$tok = strtok($server, " "); // Start tokenising the
server line
if($tok) // Get rid
of 'Server: ' entry
{
$tok = strtok(" "); // Now start
retrieving the server entries
while($tok)
{
if($tok[0] == "(") // Apache
reports itself as Apache/x.x.x (Platform)
{
$server_list[$idx-1]["server"] .= " ". $tok; // Concatenate info to
last server
}
else
{
$pos = strpos($tok, "/"); // If there's
a '/' we/ve got server and
//
version information
if($pos == 0)
{
$server_list[$idx]["server"] = $tok; // Store the server
name
}
else
{
$server_list[$idx]["server"] = substr($tok, 0, $pos); // Store the server name
$server_list[$idx]["version"] = substr($tok, $pos + 1); // Store the server
version
}
$idx++; // Increment
server index
}
$tok = strtok(" "); // Get next
server (if any)
}
}
}
return $server_list; //
Return $server_list or false if not present
}
function GetServerInfo($host, $port = 80)
{
$server = false; // Set return
value to false initially
if($fp = fsockopen($host, $port)) // Open a
connection to host:port
{
fputs($fp, "HEAD / HTTP/1.0\n\n"); // Request
the header of the site's default page
fputs($fp, "Host: $host\n");
fputs($fp, "Connection: close\n\n");
while(!feof($fp)) // Read in
the header line by line
{
$hdr = fgets($fp, 128);
if(strncmp($hdr, "Server:", 7) == 0) // Have we
got 'Server: ' yet?
{
unset($server);
$server = $hdr; //
Store it in the return value
break;
}
}
fclose($fp);
}
return $server;
}
</script>
<!--
************************************ Example usage
************************************
-->
<html>
<head>
<title>Example of server information usage</title>
</head>
<body bgcolor="#FFFFCC">
<center>
<p>
<h3>
Server information
<br>
Host: <?php echo $server; ?>
</h3>
</p>
<script language="php">
if(empty($server))
{
$server = "";
}
if($server != "")
{
$serv = GetServerList($server);
echo "<table width=\"50%\" border=\"1\" align=\"center\">\n";
echo "<tr>\n";
echo "<th>Server/Extension</th>\n";
echo "<th>Version</th>\n";
echo "</tr>\n";
for($i=0; $i<sizeof($serv); $i++)
{
echo "<tr>\n";
echo "<td width=\"50%\">\n";
echo $serv[$i]["server"];
echo "</td>\n";
echo "<td width=\"50%\" align=\"right\">\n";
echo $serv[$i]["version"];
echo "</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
}
</script>
<br>
<form target="<?php echo $PHP_SELF; ?>" method="post">
Host to query
<input type="text" width="40" name="server">
<input type="submit">
</form>
Host should be something like 'www.php.net'
<br>
<br>
(c) <a href="mailto:sbooth@ukonline.co.uk">Simon Booth</a> 2000
</center>
</body>
</html> |
|
| Gets the browser and OS from the $_SERVER['http_user_agent'] variable in PHP Categories : PHP, HTTP, Regexps | | | Remote File Saving with PHP - Download and serve a remote file. The content of the file will be updated at fixed intervals. Categories : PHP, Filesystem, Cache, Sockets, HTTP | | | A function to check if a URL exists Categories : PHP, CURL, HTTP | | | WebServerSpy checks which kind of Webserver is running, Apache, Netscape, Fasttrack, IIS, HTTP-Header, HTTP 1.0, GET, spy, WWW Categories : HTTP, Network, Apache, PHP, Web Servers | | | Simple pipe delimited file export program that downloads to a local machine Categories : PHP, Filesystem, Databases, MySQL, HTTP | | | PHP4 HTTP Compression Speeds up the Web Categories : PHP, Zlib, HTML and PHP, HTTP, Network | | | Authentication HTTP protocol POST Categories : Authentication, HTTP, PHP | | | This gets the http response headers for a given url and returns them in an assoc array. i.e. to test if a url exists: $array = get_http_headers($url); if($array[result]=200) { } Categories : HTTP, Arrays, PHP | | | Remote File Size Categories : PHP, Filesystem, HTTP, Sockets | | | Class that allows the PHP developer to create and manage UNIX like password files suitable for use as Apache authentication password files.
Categories : HTTP, PHP, PHP Classes, Filesystem | | | How to force the user to download a file instead of opening it up in an
controlled environment within the browser (i.e. MS Word/Adobe Acrobat) Categories : Browsers, PHP, HTTP | | | This script shows you the 7th latest php items from the mailing list archive on zend.com Categories : HTML, HTML and PHP, HTTP, PHP | | | Gonx Proxy - This class is meant to act as an HTTP proxy to serve pages of a remote server as if they were local pages.
Categories : PHP, PHP Classes, HTTP | | | The first step Guest Book ... ^^ Categories : MySQL, PHP, Apache, HTML, HTTP | | | Check whether your referer is coming from your website or from someone
else's.
Very useful when you want to represent the data without your domain
name for internel link-mapping in some COUNTER. Categories : PHP, HTTP | |
|
|
|