curl 获取绑定ip的url连接的头信息

直接上代码:curl

function get_header( $url , $host_ip = null){
            $ch  = curl_init();  //curl初始化
           
            if(!is_null($host_ip)){//须要绑定ipurl

                $urldata = parse_url($url);ip

                //url有参数get

                if (!empty($urldata['query']))
                    $urldata['path'] .= "?".$urldata['query'];域名

                //域名设置
                $headers = array("Host: ".$urldata['host']);
                curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);it


                //须要绑定的ip
                $url = $urldata['scheme']."://".$host_ip.$urldata['path'];
                
            }
           
            curl_setopt($ch,  CURLOPT_URL, $url);//获取的地址io

            curl_setopt ($ch, CURLOPT_HEADER, 1);//获取头信息
            curl_setopt($ch, CURLOPT_NOBODY,1);//body信息不获取
            curl_setopt($ch,  CURLOPT_RETURNTRANSFER, true);
            $result = curl_exec ($ch);function


            //var_dump($result);
            curl_close ($ch);//关闭curl
            return  $result;top

         }
query

相关文章
相关标签/搜索