<?php
define('ROOT_DIR', '.' );
define('SYSTEM_DIR' , ROOT_DIR . '/system');
require_once ( SYSTEM_DIR . '/data/config.php');
include_once ( SYSTEM_DIR . '/classes/templates.class.php');

function reset_url($url) {
	$value = str_replace ( "https://", "", $url );
	$value = str_replace ( "http://", "", $url );
	$value = str_replace ( "www.", "", $value );
	$value = explode ( "/", $value );
	$value = reset ( $value );
	return $value;
}

$url = rawurldecode ( $_GET['url'] );
$url = @base64_decode ( $url );
$url = str_replace ( "&amp;", "&", $url );

$_SERVER['HTTP_REFERER'] = reset_url ( $_SERVER['HTTP_REFERER'] );
$_SERVER['HTTP_HOST'] = reset_url ( $_SERVER['HTTP_HOST'] );

if (($_SERVER['HTTP_HOST'] != $_SERVER['HTTP_REFERER']) or $url == "") {
	@header ( 'Location: /index.php' );
	die ( "Access denied!!!<br /><br />Please visit <a href=\"/index.php\">{$_SERVER['HTTP_HOST']}</a>" );
}

$tpl = new dle_template;
$tpl->dir = ( ROOT_DIR.'/templates/');

$tpl->load_template('redirect.tpl');
$tpl->set('{title}', $config['short_title']);
$tpl->set('{home_url}', $config['http_home_url']);
$tpl->set( '{url}', $url );
$tpl->compile( 'redirect' );
$tpl->clear();

echo $tpl->result['redirect'];
die();

//@header ( 'Location: ' . $url );

//die ( "Link Redirect:<br /><br />Please click <a href=\"{$url}\">here.</a>" );
?>