This article mainly introduces php's simple method of restoring a short website, using the website administrator's short website t. cnheEHwk is used as an example to describe how to restore a short URL in php. it is very simple and practical. if you need it, you can refer to the following example to describe how to restore a short URL in php. We will share this with you for your reference. The details are as follows:
Here is the http://www.bitsCN.com of the short Web site http://t.cn/heehwkas an example to run the effect as below:
The code is as follows:
<? Php $ info1 = 'dear! You cannot resolve such short URLs. '; $ Info2 =' dear! Failed to parse the URL. please try again. '; $ Info3 ='
Access Now>'; $ Info5 =' dear! It is not a short URL or is invalid. '; Function unshort ($ url) {global $ info1, $ info2, $ info3, $ info4; $ curl = curl_init (); curl_setopt ($ curl, CURLOPT_URL, $ url ); curl_setopt ($ curl, expires, 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_E NCODING, 'gzip '); $ data = curl_exec ($ curl); if (! Empty ($ data) {$ message = curl_getinfo ($ curl); curl_close ($ curl); $ status = $ message ['http _ Code']; if ($ status = '000000' | $ status = '000000') {$ UrlHeader = (get_headers ($ url, 1 )); $ unurl = $ UrlHeader [Location]; if (is_array ($ unurl) {$ unurl = $ unurl [0]; $ unurl. = $ info3. $ unurl. $ info4; return $ unurl;} else {$ unurl. = $ info3. $ unurl. $ info4; return $ unurl;} return $ info1;} return $ info2;} function ad Funshort ($ url) {global $ info3, $ info4, $ info5; $ c = file_get_contents ($ url); $ p = "/url = '(. *) ';/isU "; preg_match ($ p, $ c, $ content); $ unurl = $ content [1]; if ($ unurl = '') {return $ info5;} else {$ unurl. = $ info3. $ unurl. $ info4; return $ unurl ;}}?><? Php $ turl = $ _ POST ['twurl']? $ _ POST ['twurl']: ""; $ url_done =$ _ POST ['url _ done']? $ _ POST ['url _ done']: ""; if ($ url_done = 'done') {$ http = substr ($ turl ); 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 actual website is:
$ Longurl ";}?>
In addition,This site also provides a short URL generation tool. the specific links are as follows:
Http://tools.bitsCN.com/password/dwzcreate