This article describes the simple implementation of PHP short URL restore method. Share to everyone for your reference, specific as follows:
Here take the cloud-dwelling community http://www.jb51.net short URL http://t.cn/heEHwk as an example to run the effect of screenshot as follows:
The specific code is as follows:
<?php $info 1 = ' Pro! Temporarily unable to resolve such short URLs.
'; $info 2 = ' Pro! URL resolution failed, please try again.
';
$info 3 = ' <br/><b><a href= ';
$info 4 = ' target= ' _blank ' > Immediate access >></a></b> '; $info 5 = ' Pro! Not a short URL or invalid.
';
function Unshort ($url) {global $info 1, $info 2, $info 3, $info 4;
$curl = Curl_init ();
curl_setopt ($curl, Curlopt_url, $url);
curl_setopt ($curl, curlopt_returntransfer,1); curl_setopt ($curl, Curlopt_useragent, ' mozilla/8.0 (compatible; MSIE 8.0;
Windows 7 ');
curl_setopt ($curl, Curlopt_header, 1);
curl_setopt ($curl, curlopt_nobody, 0);
curl_setopt ($curl, Curlopt_timeout, 15);
curl_setopt ($curl, curlopt_encoding, ' gzip ');
$data = curl_exec ($curl);
if (!empty ($data)) {$message = Curl_getinfo ($curl);
Curl_close ($curl);
$status = $message [' Http_code '];
if ($status = = ' 1 ' | | | $status = = ' 302 ') {$UrlHeader = (get_headers ($url,));
$unurl = $UrlHeader [Location];
if (Is_array ($unurl)) {$unurl = $unurl [0];
$unurl. = $info 3. $unurl. $info 4;
return $unurl;
} else {$unurl. = $info 3. $unurl. $info 4;
return $unurl;
} return $info 1;
return $info 2;
function Adfunshort ($url) {global $info 3, $info 4, $info 5;
$c = file_get_contents ($url);
$p = "/url = ' (. *) ';/isu";
Preg_match ($p, $c, $content);
$unurl = $content [1];
if ($unurl = = ") {return $info 5;
else {$unurl. = $info 3. $unurl. $info 4;
return $unurl; }?> <form action= "" method= "post" > Short URL: <input type= "text" name= "Turl" class= "inurl" size= ""/> <inp UT type= "hidden" name= "Url_done" value= "Done"/> <input "submit" type= "submitted" value= "class=" Suburl/>
> <div id= "Trurl" > <?php $turl = $_post[' Turl ']?$_post[' Turl ']: "";
$url _done= $_post[' url_done ']?$_post[' Url_done ']: "";
if ($url _done = = ' Done ') {$http = substr ($turl, 0,7);
if ($http!= ' http://' && $http!= ' https:/') {$turl = ' http://'. $turl;
$tturl = substr ($turl, 0,11); if ($tturl = = ' HTTP://ADF. ')
{$longurl = Adfunshort ($turl); }else {$Longurl = Unshort ($turl); }echo "Short url". $turl. "The real site is: <br/> $longurl";
>
In addition, the site also provides a short URL generation tool, specific links are as follows:
Http://tools.jb51.net/password/dwzcreate
More about PHP related content to view the site topics: "PHP Encryption Method Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP operation Office Document Skills Summary (including Word,excel, Access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.