PHP simple implementation of short URL (short-chain) Restore method (test available), PHP restore _php Tutorial

Source: Internet
Author: User
Tags getting started with php

PHP simple implementation of short URL (short-chain) Restore method (test available), PHP restore


In this paper, a simple way to achieve short URL restoration is described in PHP. Share to everyone for your reference, as follows:

Here to help the home http://www.bkjia.com short URL Http://t.cn/heEHwk For example, the results are as follows:

The specific code is as follows:

<?PHP$INFO1 = ' Pro! This type of short URL cannot be resolved temporarily. '; $info 2 = ' Pro! URL parsing failed, please try again. '; $info 3 = '
Visit >> now'; $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 = = ' 301 ' | | $status = = ' 302 ') {$UrlHeader = (get_headers ($url, 1)); $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; }}?><?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 URL is:
$longurl ";}? >

In addition, This site also provides a short URL generation tool, specific links are as follows:

Http://tools.jb51.net/password/dwzcreate

Read more about PHP Topics: Php encryption method Summary, PHP operations and Operator Usage Summary, PHP Network Programming Tips Summary, PHP Basic Grammar Primer Tutorial, PHP Operations Office documentation Tips Summary (including Word,excel, access,ppt), "PHP Date and Time usage summary", "PHP primer for Object-oriented programming", "PHP String Usage Summary", "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"

I hope this article is helpful to you in PHP programming.

http://www.bkjia.com/PHPjc/1125896.html www.bkjia.com true http://www.bkjia.com/PHPjc/1125896.html techarticle php Simple implementation of short URL (short-chain) Restore method (test available), PHP restore This article describes the simple implementation of PHP short URL restore method. Share to everyone for your reference, as follows ...

  • Related Article

    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.