Software, your way.
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!

Snoop-a-page

View the source code of any document at any public URL as provided by the server. And a bonus, see the header information the server returned with the document.

View the source code as received from the server, without any browser modifications:

  1. See how certain things are coded to learn how they're done.

  2. See exactly what the browser receives from the server to help figure out why a page is behaving incorrectly.

    This can be a great debugging tool for site developers.

View the header information received from the server:

  1. See what kind of server is being used, the content type, version, date, and perhaps other information (different servers will send different information).

  2. See details of cookies being set.

    See any cookie's name, value, duration, and path that is being set with PHP (but not JavaScript-set cookies, as those are set after the page is received from the server).

  3. Determine redirect trails – the URLs a browser is redirected from and to before it reaches its destination.

    The header information can be useful for site developers to see exactly what redirect the .htaccess file is sending to the browser.

    The information is useful for anyone who wants to follow redirect trails – to see how spammers redirect from country to country, for example.

The Snoop-a-page software is available for copying further below. Save it on your server as a PHP page. No customization required.

About the Document Source Code

Whatever URL you use to request a document, you'll get something back (provided the URL is to a real website).

If a web page is requested, you'll see the source code of the web page as provided by the server. If an image is requested, the source code of the image. Similarly with PDF, JavaScript, and CSS documents.

Some browsers modify the source code before publishing the page. The "view source" information is then of the modified code.

With Snoop-a-page, you'll see the source code before any browser modification is applied to it. The source code will be the source code the server responded with.

If a web page was requested that contained PHP code, the PHP code is processed on the server before responding with the document. Thus, you won't see the PHP code.

About the Header Information

The header information will be as received from the server.

There will always be some header information. The browser (or robot) needs to know the content type, for example, to know what to do with it.

We use the server information in response headers to determine whether or not it's a Unix/Linux server that can run Willmaster.com software. The server generally doesn't state the operating system type. However, if the server is Apache, it's a pretty good bet the operating system is Unix/Linux.

Generally, the less server information the better, though. Servers that respond with

If the document at the requested URL is a 404 or is intended to be redirected, you'll see it in the header information provided by the server. If a redirect, you'll see if it's 301 or 302.

If the request resulted in an internal server error, the header information will let you know.

In essence, when software (browsers, robots, Snoop-a-page, etc.) makes a request for a document, the header information the server returns with the document helps the software decide how to handle it.

The Snoop-a-page Software

Here is the source code of the Snoop-a-page software. The software is PHP.

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>Snoop-a-page</title>
<style type="text/css">
body { margin:0; font-family:sans-serif; font-size:14px; text-align:left; }
p, li { font-size:1em; line-height:120%; }
h1 { font-size:1.8em; }
h3 { font-size:1.3em; }
a { text-decoration:none; color:#1c5292; font-weight:bold; }
a, a img { border:none; outline:none; }
#content { margin:0 0 0 150px; padding:75px 0 100px 50px; width:550px; border-left:6px groove #2F83E5; }
</style>
</head>
<body><div id="content">

<div style="position:fixed; left:50px; top:50px;">
<a href="//www.willmaster.com/">
<img src="//www.willmaster.com/images/wmlogo_icon.gif" style="width:50px; height:50px; border:none;" alt="Willmaster logo">
</a>
</div>

<h1>Snoop-a-page</h1>

<?php
/* 
   Snoop-a-page
   Version 1.0
   May 20, 2013

   Will Bontrager Software, LLC
   https://www.willmaster.com/
   Copyright 2013 Will Bontrager Software, LLC

   This software is provided "AS IS," without 
   any warranty of any kind, without even any 
   implied warranty such as merchantability 
   or fitness for a particular purpose.
   Will Bontrager Software, LLC grants 
   you a royalty free license to use or 
   modify this software provided this 
   notice appears on all copies. 
*/
function DeliverPage()
{
   $URL = $_POST['URL'];
   $url = preg_replace('/^https?:\/\//i','',$URL);
   @list($host,$uri) = explode('/',$url,2);
   $domain = strtolower($host);
   $uri = "/$uri";
   $version = '1.0';
   if( preg_match('/^https:/i',$URL) )
   {
      echo '<script type="text/javascript">alert(\'Use only http://... URLs, not https://...\');</script>';
   }
   $headsend = "GET $uri HTTP/$version\r\nHost: $host\r\nAccept: */*\r\nConnection: Close\r\n\r\n";
   $fp = @fsockopen($host,80,$errno,$errstr,20);
   if( ! $fp ) { return "Error number: $errno<br />Error string: $errstr<br>Domain: $host<br />URI: $uri"; }
   fwrite($fp,$headsend);
   $content = '';
   while (!feof($fp)) { $content .= fgets($fp,1024); }
   fclose($fp);
   echo "<hr><h4 style='margin:0;'>Header returned from $URL</h4><hr><pre>";
   $pos = strpos($content,"\r\n\r\n");
   echo substr($content,0,$pos);
   echo "</pre><hr><h4 style='margin:0;'>Content returned from $URL</h4><hr><pre>";
   echo htmlspecialchars( substr($content,$pos+4) );
   echo '</pre><hr>';
}
if( isset($_POST['URL']) ) { DeliverPage(); }
?>

<form style="margin-top:100px;" method="post" action="<?php echo($_SERVER['PHP_SELF']); ?>">
URL to request:<br>
<input type="text" name="URL" value="<?php if(isset($_POST['URL'])){echo($_POST['URL']);} ?>" style="width:400px;"><br>
<input type="submit" value="Get document and header info" style="width:400px;">
</form>

<p style="margin:35px 0 75px -35px;">
Copyright 2013 <a href="//www.willmaster.com/">Will Bontrager Software, LLC</a>
</p>
</div>
</body>
</html>

Copy the source code of the Snoop-a-page software and save it to your server as a PHP page. Give it file name snooper.php (or other .php name if you prefer).

You're now able to request a document from any URL and see both the header information and the source code of the document as the server provides them.

A handy tool to have around. Especially for site developers.

Snooper 3-Pack (with Spoofer Bonus)

Snooper 3-Pack (with Spoofer Bonus) is a WebSite's Secret member exclusive.

In addition to header information and document source code, it also (optionally) retrieves the domain registration information.

As a bonus, the following information can be spoofed when requesting a document from a server:

  1. The referrer. The referrer is the URL of the web page where the browser/robot came from, generally the URL of a web page where a link was clicked to get to the current page. Referrer information is voluntary and may be omitted.

    This can be useful to see if a server delivers a different version of a web page when browsers say they come from certain other places, like a URL from their own website or a URL from China, for examples.

  2. Identification. The user-agent string is voluntary and identifies the browser/robot. The information can be whatever the software decides to identify itself as. If the user-agent string is omitted, software on the server may deny the page.

    This can be useful to see if a server delivers a different version of a web page when the Snooper 3-Pack identifies itself in different ways, as Googlebot or as an iPhone, for examples.

If you could use the extra functionality Snooper 3-Pack provides, get a WebSite's Secret membership. This is a permanent membership that never expires. No renewals – ever.

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