PHP retrieves the website icon (favicon. ico) File

Source: Internet
Author: User
Some website source codes include 1linkrelw.cuticonhreffavicon. icotypeimagex-icon or 1linkreliconhreffavicon. icotypeimagex-icon to specify the icon location. However, most browsers support automatic retrieval.

Some website source codes include: 1 link rel = "shortcut icon" href = "/favicon. ico "type =" image/x-icon "/or 1 link rel =" icon "href ="/favicon. ico "type =" image/x-icon. However, most browsers support automatic retrieval.

YesWebsiteThese lines of code are added to the source code:

1 
 

Or

1 
 

You can specifyIconLocation storage.

However, most browsers currently support automaticObtainWebsite. Ico under the root directoryFileSo the lines of code cannot be seen in the source code.

Feasible Method:

  

1 // get every url,ObtainIcon 2 $ url = $ matches [1] [$ I]; 3 $ contents = @ file_get_contents ($ url); 4 preg_match ('/
 /', $ Contents, $ icon); 5 if (! Empty ($ icon) {6 // print_r ($ icon [1]); 7 echo"
"; 8 $ array = @ get_headers ($ icon [1], 1); 9 if (preg_match ('/ 200/', $ array [0]) {10 // echo"
"; 11 print_r ($ icon [1]); 12 echo" $ icon [1]. "'>; 13 // echo" string "; 14 // print_r ($ array ); 15} else {16 // remove the redundant slash 17 $ url = substr_replace ($ url, "",-1); 18 echo "invalid url resource! ". $ Url. $ icon [1]; 19 echo "$ url. $ icon [1]. "'>; 20} 21 22} else {23 // here I tried many methods. Later I found that the url can be used to capture the root directory of the url, due to the habitualFileThe name is favicon. ico, so you can directly access a url like this to getIconFile, Http://wenwen.sogou.com/favicon.ico24 $ url = substr ($ url, 7); // remove the first 25 $ position = strpos ($ url, '/'); 26 $ url = substr ($ url, 0, $ position); 27 echo "$ url. "/favicon. ico '>; 28 // echo $ url. "/favicon. ico
"; 29 // judgmentWebsiteWhether the root directory of. icon existsFile30 // $ url = 'HTTP ://'. $ _ SERVER ['server _ name']. $ _ SERVER ["REQUEST_URI"]; 31 // echo dirname ($ url); 32 // if (file_exists ("favicon. ico ") 33 // echo"

Exist

"; 34}

  Ideas:

First, determine whether there are several lines of code added to iocn in the source code. If there is one, directly capture the code, then determine whether the code is a valid url, and then determine whether the code is displayed. If notObtainThe root directory is displayed.

  

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.