What Is It Really Doing?
When you load a web page, do you watch your browser's address bar?
The page may be redirecting to a different page — for benevolent or nefarious reasons.
Perhaps the page is redirecting through a click counter (which Possibilities ezine links do). Perhaps it's an affiliate link that needs to be redirected through a merchant's cookie-setting page. Perhaps the page has moved to a new location.
Or, perhaps it's a spammer's URL that would redirect your browser to a log-in phishing or malware download page.
Whenever there's reason for concern about a URL, or an intuitive hint of it (or a curiosity), find out whatever you can about what the URL sends to your browser.
Software to Do It With
The HTTP Request Information software that comes with this article can tell you exactly what your browser would have received — including the header information.
No JavaScript is run. No redirects are followed.
You get the destination web page and its header (if they're available) and a bunch of information about the HTTP request — that might come in handy if you're seriously investigating a URL. The information generally includes page size, download speed, and content type.
Other Things That Might Baffle
When you click a link and don't get the page you expected and, instead, get what might be a generic page that indicates an error of some kind, you're unlikely to be told what type of error it is. Only an indication that something's wrong.
Is it a 403 Forbidden, a 404 Not Found, a 500 Internal Server Error, or something else?
This could happen on your own web site, too, if you have generic error pages set up. It could play havoc when trying to find out what's wrong so you can fix it.
Software to the Rescue
The software with this article can reveal those error codes. (Actually, they're called status codes. All URL requests get a status code even when there is no error.)
Give the software the URL of the problematic page and it lets you know what it finds.
You can use HTTP Request Information right on this page. Or, you can download it for use on your own domains.
Using HTTP Request Information on This Page
The HTTP Request Information used here has been modified to work only with Ajax to prevent linking to script from remote locations. Publisher logos and links have been omitted for better display within this web page.
Type in the URL to check. The result will be inserted on this page immediately below the form. (Because no redirects are followed, you get to see the response at the URL your specify — rather than the response after all redirects have been accomplished.)
HTTP Request Information for Use on Your Domains
Here is the HTTP Request Information software. Below the source code are instructions for installing and using it on your domains.
<?php
/*
HTTP Request Information
Version 1.0
October 15, 2016
Will Bontrager Software LLC
https://www.willmaster.com/
Copyright 2016 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
this software provided this notice appears on all copies.
*/
mb_internal_encoding('UTF-8');
date_default_timezone_set('UTC');
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
$url = isset($_POST['url']) ? $_POST['url'] : false;
function GetWebPage( $url, &$content )
{
global $Version;
$options = array(
CURLOPT_RETURNTRANSFER => true, // Return web page
CURLOPT_HEADER => true, // Return headers
CURLOPT_CONNECTTIMEOUT => 120, // Timeout on connect
CURLOPT_TIMEOUT => 120, // Timeout on response
CURLOPT_FOLLOWLOCATION => false, // Don't Follow redirects
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'],
CURLOPT_VERBOSE => false
);
$info = array();
$ch = curl_init($url);
curl_setopt_array($ch,$options);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch) ;
$info = curl_getinfo($ch);
curl_close($ch);
$info['errno'] = $err;
$info['errmsg'] = $errmsg;
return $info;
} # function GetWebPage()
?><!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Access a Web Page</title>
<style type="text/css">
html, body { font-size:100%; font-family:sans-serif; }
h1 { font-size:1.8em; }
p { font-size:1em; }
pre { font-size:1.2em; }
.color { background-color:#cceeff; font-weight:bold; padding:.25em 1em .25em 1em; border:1px solid #6666ff; border-radius:.25em; }
.invisible { color:#cceeff; }
input { width:100%; box-sizing:border-box; font-size:1em; }
a { text-decoration:none; }
</style>
</head>
<body>
<div style="max-width:5in; margin:.5in auto; background-color:transparent;">
<div style="float:left;"><a href="//www.willmaster.com/"><img src="//www.willmaster.com/images/wmlogo_icon.gif" style="border:none; outline:none; height:50px; width:50px;" alt="Willmaste.rcom logo"></a></div>
<h1 style="padding-top:9px; padding-left:55px; margin:0;"><a href="//www.willmaster.com/" style="color:black;">Willmaster.com</a></h1>
<div style="clear:left; height:.1em;"></div>
<form method="post" enctype="multipart/form-data" accept-charset="utf-8" action="<?php echo(htmlspecialchars($_SERVER['PHP_SELF'])); ?>">
<p>
URL: <input type="text" name="url" value="<?php echo(htmlspecialchars(@$_POST['url'])) ?>">
</p>
<p>
<input type="submit" value="Retrieve<?php if($url): ?> another<?php endif; ?> URL">
</p>
</form>
<p>
Copyright 2016 <a href="//www.willmaster.com/">Will Bontrager Software LLC</a>
</p>
</div>
<?php if($url): ?>
<p class="color">Page information for URL <?php echo($url) ?></p>
<?php
$content = '';
$info = GetWebPage($url,$content);
echo '<div style="max-height:2in; max-width:7in; margin:.5in auto; border:1px solid black; padding:1em; overflow:auto;"><p class="color" style="margin-top:0;">Array of raw page-retrieval information that might or might not be pertinent:</p><pre>',print_r($info,true),'</pre></div>';
$message = 'Here are <br><span class="invisible">ii</span>(i) the web page header lines as returned from the server, <br><span class="invisible">i</span>(ii) a blank line, and <br>(iii) the source code of the web page.';
if( strlen(trim($content)) < 3 )
{
$content = '';
$message = 'No content received.';
}
echo "<div style=\"margin:.5in;\"><p class=\"color\" style=\"display:table; margin-bottom:0;\">$message</p><pre>".htmlspecialchars($content).'</pre></div>';
?>
<?php endif; ?>
</body>
</html>
Instructions:
-
Copy the source code and save it as RequestInfo.php or other .php file name of your preference. (No customization is required.)
-
Upload RequestInfo.php to your server and make a note of its URL.
-
Type the URL into your browser's address bar.
When something seems to be awry with a web page, or you're just curious, use HTTP Request Information to investigate.
(This article first appeared in Possibilities ezine.)
Will Bontrager