<?php
	// global definitions and variables
	$delay = "6"; // in seconds
	$url = urldecode($_SERVER["QUERY_STRING"]);
	
	if ($url == NULL) {
			$url = "https://www.startpage.com/";
		}
	
	// only allow http/https urls
	$pat = '/^http(s)?/i';
	if (!preg_match($pat, $url)) {
		die("Invalid request, only http and https links are valid options!");
	}
	
	

	// preventing XSS
	$url = str_replace("\"", "%22", $url);
	$url = str_replace("'", "%27", $url);

	// truncate for target page	
	$gotodest = (strlen($url) > 55) ? substr($url, 0, 52) . "[..]" : $url;
	$gotodest  = htmlentities($gotodest, ENT_QUOTES);
	
	//<div style="background: #DADADA; position: absolute; width: 70%; height: 160px; line-height: 40px; left: 80px; top: 30%; margin-left: -20px; margin-top: -40px; border: 1px dotted #000000; text-align: center;">
?>
<!DOCTYPE html>

<html>
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="refresh" content="<?=$delay?>; URL='<?=$url?>'" />
		<meta name="referrer" content="no-referrer" />
		<title>Redirect to <?=$gotodest?></title>
		<script language="JavaScript" type="text/javascript">
			var seconds = <?=$delay?>;
			var url="<?=$url?>";

			function redirect(){
				if (seconds <=0){
				// redirect to new url after counter  down.
				window.location = url;
				}else{
				seconds--;
				document.getElementById("pageInfo").innerHTML = "Redirecting in " + seconds + " second(s)."
				setTimeout("redirect()", 1000)
				}
			}
</script>
	</head>
	<body>

		
	
		<div style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #000000; text-align: center;">
			<p>You are now leaving for the open wide internet... don't trust anyone out there!</p>
			<p>Your destination:</p>
			<p><b><a href="<?=$url?>"><i><?=$gotodest?></i></a></b></p>
			<div id="pageInfo">
			<p><script>
				redirect();
			</script></p>
			</div>
		</div>

	</body>
</html>

