如何查找使用PHP的域是HTTP还是HTTPS(带有或不带有WWW)? [英] How to find the domain is whether HTTP or HTTPS (with or without WWW) using PHP?

查看:160
本文介绍了如何查找使用PHP的域是HTTP还是HTTPS(带有或不带有WWW)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有百万(1,000,000)个列表.

I have million (1,000,000) domains list.

+----+--------------+--------------------------+
| Id | Domain_Name  |       Correct_URL        |
+----+--------------+--------------------------+
|  1 | example1.com | http://www.example1.com  |
|  2 | example2.com | https://exmple2.com      |
|  3 | example3.com | https://www.example3.com |
|  3 | example4.com | http://example4.com      |
+----+--------------+--------------------------+

  • IDDomain_Name列已填充.
  • Correct_URL 列为空.
    • ID and Domain_Name column is filled.
    • Correct_URL column is empty.
    • 问题:我需要填写Correct_URL列.

      我面临的问题是如何在域之前找到前缀部分.它可能是http://http://www.https://https://www.

      The problem I face is how do I find the prefix part before the domain. It may either http:// or http://www. or https:// or https://www.

      如何使用PHP正确找到上述4种内容?请注意,我需要在所有1,000,000个域中运行代码....因此,我正在寻找一种检查它的最快方法...

      How do I find correctly what is from above 4 using PHP? Please note that I need to run code to all 1,000,000 domains.... So I am looking at a fastest way to check it...

      推荐答案

      您可以使用cURL方法:

      $url_list = ['facebook.com','google.com'];
      
      foreach($url_list as $url){
      
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
          curl_exec($ch);
      
          $real_url =  curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
          echo $real_url;//add here your db commands
      
      }
      

      此操作需要花费一些时间,因为它需要使用上次重定向的URL.如果您只想查看其httphttps,则可以尝试以下操作:

      This one take some times because it take the last redirected url. if you only want to check whether its http or https you could try this:

      $url_list = ['facebook.com','google.com'];
      
      foreach($url_list as $url){
      
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_exec($ch);
      
          $real_url =  curl_getinfo($ch, CURLINFO_REDIRECT_URL);
          echo $real_url;//add here your db commands
      
      }
      

      这篇关于如何查找使用PHP的域是HTTP还是HTTPS(带有或不带有WWW)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆