해결 file_get_콘텐츠가 https 연결을 요청할 수 없는 방법

오류: Warning: fopen () [function.fopen]: Unable to find the wrapper "https"- did you forget to enable it when you configured PHP?
솔루션은 다음과 같습니다.
1. 윈도우즈 아래의 PHP는 php까지만 가능합니다.ini에서 extension=php_openssl.dll 앞의 것;지우고 서비스를 다시 시작하면 됩니다.
2. linux 아래의 PHP는 반드시 Openssl 모듈을 설치해야 합니다. 설치가 다 된 후에 접근할 수 있습니다.
3. 서버에서 설정을 수정할 수 없으면curl 함수를 사용하여 file_get_콘텐츠 함수, 물론 간단한 교체는 아니죠.상응하는 매개 변수 설정이 있어야curl 함수를 정상적으로 사용할 수 있습니다.
curl 함수에 대한 패키지는 다음과 같습니다.

function http_request($url,$timeout=30,$header=array()){ 
        if (!function_exists('curl_init')) { 
            throw new Exception('server not install curl'); 
        } 
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($ch, CURLOPT_HEADER, true); 
        curl_setopt($ch, CURLOPT_URL, $url); 
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
        if (!emptyempty($header)) { 
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
        } 
        $data = curl_exec($ch); 
        list($header, $data) = explode("\r
\r
", $data); 
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
        if ($http_code == 301 || $http_code == 302) { 
            $matches = array(); 
            preg_match('/Location:(.*?)
/', $header, $matches); 
            $url = trim(array_pop($matches)); 
            curl_setopt($ch, CURLOPT_URL, $url); 
            curl_setopt($ch, CURLOPT_HEADER, false); 
            $data = curl_exec($ch); 
        } 

        if ($data == false) { 
            curl_close($ch); 
        } 
        @curl_close($ch); 
        return $data; 

좋은 웹페이지 즐겨찾기