Parse the URL of Baidu search result link, get the real URL

Source: Internet
Author: User

Usually, in the Baidu keyword search appears in the list page, click on the target link, but when the jump is Baidu address, after Baidu analysis, really jump to the target page.

In the SEO, often need to look at their own site rankings, and do not want to manually go to point manual every day, the following methods can be used to get the target address.

The principle is quite simple: simulate the request and get the real address.

<?PHP$url= "Http://www.baidu.com/link?url=nS2MGJqjJ4zBBpC8yDF8xDh8vibi1lVeE7gGr9UONBu";$info=Parse_url($url);$fp=Fsockopen($info[' Host '], 80,$errno,$errstr, 30);fputs($fp, "GET {$info[' Path ']}? {$info[' Query ']} Http/1.1\r\n ");fputs($fp, "Host: {$info[' Host ']} \ r \ n ");fputs($fp, "connection:close\r\n\r\n");$rewrite= ' '; while(!feof($fp)) {    $line=fgets($fp); if($line! = "\ r \ n" ) {        if(Strpos($line, ' location: ')!==false) {            $rewrite=Str_replace(Array("\ r", "\ n", "Location:"), ",$line); }    }Else {         Break; }}Var_dump($rewrite);//results shown: string "http://www.google.com/"?>

Resolves http://www.baidu.com/link?url=nS2MGJqjJ4zBBpC8yDF8xDh8vibi1lVeE7gGr9UONBu to http://www.google.com/

Parse the URL of Baidu search result link, get the real URL

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.