Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibrarySnooping (Information Retrieval)

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Getting Status Code and Server Type with PHP

What is Server Status Code?

A status code is a number and a label, like "404 Not Found" and "500 Internal Server Error."

What is Server Type?

The server type (the server operating system) is the software being used and, sometimes, a list of helper software.

Useful Software

That information can useful while testing software. Knowing the server type where a client's domain is on can be useful when recommending software.

Do you use .htaccess or other methods to redirect certain web pages? Use this software to verify things are working as they should. For example, if you enter "willmaster.com", you'll see both "301 Moved Permanently" and "Location: /". If you then enter "www.willmaster.com", you'll see a "200 OK" status.

How To Read the Web Page Header Information

The status code is on the first line of the information the server provides. Other information follows.

And, of course, it can also be good to see what others can see about our own servers, should they be inclined to snoop.

Determining Server Operating System

We use a version of the PHP server snooper software presented in this article to let customers test their own server to see if they meet operating system requirements. The checker is on the software description pages.

If you want to see how one works, a server type checker is on the Master Form V4 description page. Give it a spin.

Viewing Actual Redirect Status Code

Many hosting accounts are configured to redirect to a different web page when certain errors are found, like the "500." The PHP server snooper script with this article lets you see that real error code regardless which web page the hosting account is configured to display instead.

Independently obtaining a status code can be a real time saver when installing software and the server keeps spawning errors. You know what the real error code is, not just a redirect page.

Copy 'n Paste PHP Script

The PHP script that comes with this article is complete. There is nothing to add or remove or customize. Copy 'n paste.

Here is the PHP server snooper script:

<html>
<head>
<style type="text/css">
body { margin-left:200px; margin-top:50px; width:500px; font-family:verdana,sans-serif; }
input, textarea { width:500px; font-family:monospace; }
.nowrap { white-space:nowrap; }
</style>
<body>
<!-- 
To paste this form into an existing web page, copy from here 
to just above the cancel </body> tag. The web page needs to 
be PHP, usually with .php file name extension.
-->

<form method="GET" action="<?php echo($_SERVER['PHP_SELF']) ?>">
<h3><a href="/library/">Possibilities Ezine</a> Server Snooper</h3>

<?php
$host = $uri = '';
if( isset($_GET['host']) )
{
	$host = $_GET['host'];
	$uri = ( isset($_GET['uri']) and strlen($_GET['uri']) > 0 ) ? $_GET['uri'] : '/';
   $content = '';
   $fp = fsockopen("$host", 80, $errno, $errstr, 30);
   if(!$fp)
   {
      echo "$errstr ($errno)<br />\n";
      return;
   } 
   else
   {
      fwrite($fp,"HEAD $uri HTTP/1.0\r\n");
      fwrite($fp,"Host: $host\r\n");
      fwrite($fp,"Connection: Close\r\n");
      fwrite($fp,"\r\n");
      while (!feof($fp)) { $content .= fgets($fp, 128); }
      fclose($fp);
   }
   echo "<p>Results for <a href="\"http://$host$uri\">http://$host$uri</a></p>";"
   echo '<textarea cols="55" rows="9" wrap="off">';
   echo $content;
   echo '</textarea><br /><hr /><br />';
}
?>

<p>
What is the host name (the domain name without the "http://" part)?<br />
<input type="text" name="host" size="55" value="<?php echo($host) ?>">
</p>
<p>
What is the URI (the part of the URL after the domain name, or "/" if default page)?<br />
<input type="text" name="uri" size="55" value="<?php echo($uri) ?>">
</p>
<p>
<input type="submit" name="submit" value="Yes, let's snoop." style="text-align:left">
</p>
</form>

<!--
To paste this form into an existing web page, copy from just 
below the begin <body> tag to this point. The web page needs 
to be PHP, usually with .php file name extension.
-->
</body>
</html>

The PHP server snooper source code is provided as a complete web page. Upload it to your server and you're good to go. To use the software, type its URL into your browser.

If you scan the code, you'll see it has the beginning and ending marked should you wish to transfer the software to one of your existing PHP web pages. Copy the code between those marks and paste it where it is to be used.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC