<?php
class getCid
{
function __construct($username)
{
$this->username = $username;
}
function findUltimateDestination($url, $maxRequests = 10)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Link Checker)');
while ($maxRequests--)
{
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
$location = '';
if (in_array(curl_getinfo($ch, CURLINFO_HTTP_CODE), [301, 302, 303, 307, 308])) {
if (preg_match('/Location:(.*)/i', $response, $match)) {
$location = trim($match[1]);
}
}
if (empty($location))
{
return $url;
}
if ($location[0] == '/')
{
$u = parse_url($url);
$url = $u['scheme'] . '://' . $u['host'];
if (isset($u['port'])) {
$url .= ':' . $u['port'];
}
$url .= $location;
} else {
$url = $location;
}
}
return null;
}
function getCid()
{
$finalDestination = $this->findUltimateDestination('http://www.imvu.com/catalog/web_av_pic.php?av=' . $this->username);
$cid = explode("_", end(explode("/", $finalDestination)))[0];
return $cid;
}
}
$username = $_GET['username'];
if(isset($username))
{
$imvuCid = new getCid($username);
$cid = $imvuCid->getCid($username);
echo $cid;
}
else
{
echo 'Please submit a username -> ?username=xxx';
}
?>