Forum Moderators: coopster
------------------ image.php -----------------
<?php
$path = str_replace('..','',$_SERVER['QUERY_STRING']);
$fullpath = 'http://AdServerDomain.com/nserver/SITE=TEST/AREA=Front/pageid=$pageid';
header('Content-type:image/gif');
$data = file_get_contents($fullpath);
echo $data;
?>
----------------- image.php -----------------
----------------- index.php -----------------
<html>
<head>
</head>
<body>
<?
function generateRandomString($length = 15, $letters = '1234567890qwertyuiopasdfghjklzxcvbnm')
{
$s = '';
$lettersLength = strlen($letters)-1;
for($i = 0 ; $i < $length ; $i++)
{
$s .= $letters[rand(0,$lettersLength)];
}
return $s;
}
$pageid=generateRandomString();
function get_redirect_url($url){
$redirect_url = null;
$url_parts = @parse_url($url);
if (!$url_parts) return false;
if (!isset($url_parts['host'])) return false; //can't process relative URLs
if (!isset($url_parts['path'])) $url_parts['path'] = '/';
$sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : 80), $errno, $errstr, 30);
if (!$sock) return false;
$request = "HEAD " . $url_parts['path'] . (isset($url_parts['query']) ? '?'.$url_parts['query'] : '') . " HTTP/1.1\r\n";
$request .= 'Host: ' . $url_parts['host'] . "\r\n";
$request .= "Connection: Close\r\n\r\n";
fwrite($sock, $request);
$response = '';
while(!feof($sock)) $response .= fread($sock, 8192);
fclose($sock);
if (preg_match('/^Location: (.+?)$/m', $response, $matches)){
if ( substr($matches[1], 0, 1) == "/" )
return $url_parts['scheme'] . "://" . $url_parts['host'] . trim($matches[1]);
else
return trim($matches[1]);
} else {
return false;
}
}
?>
<img src="image.php?pageid=<? echo $pageid ;?>" />
<?
$clickUrl = get_redirect_url('http://AdServerDomain.com/ClickURL/SITE=TEST/AREA=Front/pageid=$pageid');
echo "$clickUrl";
?>
</body>
</html>
----------------- index.php -----------------
<html>
<head>
</head>
<body>