Where Will the Link Take You?
Have you ever hesitated before clicking on a link, wondering where it might take you?
The free PHP script in this article, Destination URL, lets you know the final URL of a link before you click on it. Simply put the script on your server and use it.
Use Destination URL for links in emails, on websites, in tweets, in ebooks, and in ads.
Destination URL
- accepts and sets no cookies,
- downloads no viruses, and
- runs no JavaScript.
The Destination URL software follows HTTP response code 301, 302, and 307 redirects and also meta tag redirects.
Because Destination URL runs no JavaScript, it follows that it also won't pursue new destinations imposed by that method. JavaScript can redirect browsers at various times, with any of several different functions, and it can be coded in numerous different ways. Scanning JavaScript and parsing it is outside the scope of Destination URL.
When you wonder about a URL, use Destination URL to determine where your browser will end up at. Then decide if you really want to visit that place.
Destination URL is free. It's a copy and paste PHP script. (In other words, no customization needed, just upload it to your server.)
Here's the source code:
<?php
/*
Destination URL
Version 1.0
January 10, 2015
Will Bontrager Software LLC
https://www.willmaster.com/
Copyright 2015 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.
*/
/* No customization required. */
$URL = '';
if( empty($_GET['url']) and isset($_SERVER['QUERY_STRING']) )
{
$temp = urldecode($_SERVER['QUERY_STRING']);
if( preg_match('!^https?://!i',$temp) ) { $_GET['url'] = $temp; }
}
if( isset($_GET['url']) ) { $URL = GetDestinationURL($_GET['url']); }
function GetDestinationURL($url)
{
global $Version;
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
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);
if( $info['http_code'] == 200 and preg_match('!<meta\s([^>]+)!i',$content,$match) )
{
$content = $match[1];
$match = array();
if( preg_match('!\burl\s*=\s*([^ "\']+)!i',$content,$match) )
{
$content = $match[1];
$redirectURL = preg_replace('/^[ "\']*/','',$match[1]);
return GetDestinationURL($redirectURL);
}
}
if( $info['http_code'] == 200 ) { return $url; }
if( $info['http_code'] == 301 or $info['http_code'] == 302 or $info['http_code'] == 307 ) { return GetDestinationURL($info['redirect_url']); }
if( strlen($err) and strlen($errmsg) ) { return "ERROR: $err -> $errmsg"; }
return 'ERROR: Status code ' . $info['http_code'];
}
?><!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>Destination URL</title>
<style type="text/css">
body {
color:#000000;
font-family:arial,sans-serif;
background-color:#ffffff;
text-align:left;
font-size:100%;
margin:0;
}
p {
font-size:1em;
line-height:125%;
}
h1 {
color:#999;
font-size:150%;
margin:0 0 35px 55px;
white-space:nowrap;
font-variant:small-caps;
}
h2 { font-size:125%; }
a {
text-decoration:none;
color:#1c5292;
font-weight:bold;
}
a, a img, img {
border:none;
outline:none;
}
.nowrap { white-space:nowrap; }
input {
font-size:100%;
width:98%;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
}
input[type="text"] {
font-size:100%;
border:1px solid black;
border-radius:5px;
padding:3px;
}
#content
{
padding:28px 0 0 5px;
max-width:500px;
margin:auto auto;
position:relative;
}
</style>
</head>
<body><div id="content">
<form method="get" action="<?php echo($_SERVER['PHP_SELF']); ?>">
<div style="position:absolute; left:0px; top:15px;">
<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>Destination URL</h1>
<h2>Where Will the Link Take You?</h1>
<?php if($URL): ?>
<p>
The final destination for URL
<span class="nowrap"><?php echo($_GET['url']); ?></span>
is:
</p>
<p style="margin-bottom:50px;">
<span class="nowrap"><?php echo($URL); ?></span>
</p>
<?php endif; ?>
<p>
Specify URL to follow.<br>
<input type="text" name="url" value="<?php echo(@$_GET['url']); ?>">
</p>
<p style="margin-bottom:45px;">
<input type="submit" name="submitter" value="Submit URL">
</p>
<p>
Copyright 2015 <a href="//www.willmaster.com/"><span class="nowrap">Will Bontrager Software LLC</span></a>
</p>
</form></div></body></html>
Paste the code into a plain text file and upload it to your server. Name the file DestinationURL.php or other name that makes sense to you. Because it is a PHP script, the file name needs to have the .php file name extension.
When uploaded, type the URL of the newly-uploaded DestinationURL.php into your browser and you're good to go.
Destination URL provides a form field where you can type in the URL you want to check.
Alternatively, you can also type a URL to check as a parameter to the DestinationURL.php URL. Example: http://example.com/DestinationURL.php?https://www.willmaster.com
Here are some URLs to try:
https://www.willmaster.com (click to select)
(Redirects to https://www.willmaster.com/index.php — the Willmaster.com home page.)
https://www.willmaster.com/go/PossOnline (click to select)
(Redirects to https://www.willmaster.com/possibilities/index.php — the Possibilities ezine online.)
Other URLs to try are in the Possibilities ezine itself.
Then try URLs found in tweets, URLs you get in email, and URLs in ads. Shortened URLs. URLs in ebooks.
Have Destination URL on your server ready for you to use. If you have a personal portal page, Destination URL is a handy tool to link to.
Ever wonder where a link will take you? The free Destination URL software can tell you.
(This article first appeared in Possibilities ezine.)
Will Bontrager