<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>查詢百度link?ulr=真實鏈接表單</title>
</head>
<body>
<?php
/*
getrealurl 獲取301、302重定向後的URL地址 by enenba.com
@param str $url 查詢
$return str 定向後的url的真實url
*/
function getrealurl($url){
$header = get_headers($url,1);
if (strpos($header[0],'301') || strpos($header[0],'302')) {
if(is_array($header['Location'])) {
return $header['Location'][count($header['Location'])-1];
}else{
return $header['Location'];
}
}else {
return $url;
}
}
$input = '<form method="get" action=""><input type="text" name="url" id="url" style="width:800px;" /><input type="submit" value="提交" /></form><body></html>';
$url = isset($_GET['url'])?$_GET['url']:'';
if(empty($url)) exit($input);
$urlreal = getrealurl($url);
echo '真實的url為:'.$urlreal;
$urlreal = ltrim($urlreal,'http://');
$search = '/ebac5573358cc3c0659257bfcf54([0-9a-f]+)/i';
preg_match($search,$url,$r);
$url_encode = $r[1]; unset($r);
echo '<br/>密文部分為:'.$url_encode.'<br/>';
$urlreal_arr = str_split($urlreal);
$url_encode_arr = str_split($url_encode,2);
echo '<br />';
echo $input;
?>