Php simple short URL (short URL) restoration method (available for test)

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.