2016-08-18 7 views
1

확인하기 전에 중복 된 것으로 읽으십시오. 지금은 allow_url_fopen이 사용 중지 된 URL의 내용을 반향시키고 있습니다. 모든 솔루션을 스택에 게시 해 보았습니다. 과다. 예 :file_get_contents가 페이지 내용을 검색하지 않음

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
$result = curl_exec($ch); 
curl_close($ch); 

function curl_get_contents($url) 
{ 
    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_URL, $url); 

    $data = curl_exec($ch); 
    curl_close($ch); 

    return $data; 
} 

작동하지 않습니다

$url = "http://www.google.com"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$data = curl_exec($ch); 
curl_close($ch); 
echo $data; 

fopen("cookies.txt", "w"); 
$url="http://adfoc.us/1575051"; 
$ch = curl_init(); 

$header=array('GET /1575051 HTTP/1.1', 
    'Host: adfoc.us', 
    'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 
    'Accept-Language:en-US,en;q=0.8', 
    'Cache-Control:max-age=0', 
    'Connection:keep-alive', 
    'Host:adfoc.us', 
    'User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36', 
    ); 

    curl_setopt($ch,CURLOPT_URL,$url); 
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); 
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,0); 
    curl_setopt($ch, CURLOPT_COOKIESESSION, true); 

    curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt'); 
    curl_setopt($ch,CURLOPT_COOKIEJAR,'cookies.txt'); 
    curl_setopt($ch,CURLOPT_HTTPHEADER,$header); 
    $result=curl_exec($ch); 

    curl_close($ch); 

작동하지 않습니다 작동하지 않습니다 작동하지 않습니다

// create the Gateway object 
$gateway = new Gateway(); 

// set our url 
$gateway->init($url); 

// get the raw response, ignore errors 
$response = $gateway->exec(); 

이 작동하지 않는

$file = "http://www.example.com/my_page.php"; 
if (function_exists('curl_version')) 
{ 
    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_URL, $file); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
    $content = curl_exec($curl); 
    curl_close($curl); 
} 
else if (file_get_contents(__FILE__) && ini_get('allow_url_fopen')) 
{ 
    $content = file_get_contents($file); 
} 
else 
{ 
    echo 'You have neither cUrl installed nor allow_url_fopen activated. Please setup one of those!'; 
} 

작동하지 않습니다.

file_get_contents을 사용하려고하는 페이지가 내 웹 사이트에 없습니다. 내가 페이지를 읽고 페이지에 특정 단어가 있는지 확인하여 사이트 소유자에 대한 간단한 API를 만들 수 있도록 file_get_contents을 사용하려고합니다.

그러나 사람이 어떤 제안이 있다면 그래 먼저 확인 사이트가 사용 가능하며, 예를 들어 샘플 코드가

코드 here에서 촬영되지 날씨 수 :

답변

0

아래 게시하시기 바랍니다 :

<?php 
    $cURL = curl_init('http://www.technofusions.com/'); 
    curl_setopt ($cURL , CURLOPT_RETURNTRANSFER , true); 
    // Follow any kind of redirection that are in the URL 
    curl_setopt ($cURL , CURLOPT_FOLLOWLOCATION , true); 
    $result = curl_exec ($cURL); 
    // Getting HTTP response code 
    $answer = curl_getinfo ($cURL , CURLINFO_HTTP_CODE); 
    curl_close ($cURL); 
    if ($answer == ' 404 ') { 
     echo ' The site not found (ERROR 404)! ' ; 
    } else { 
     echo ' It looks like everything is working fine ... ' ; 
    } 
    ?> 

전체 답변을 보려면이 자습서를 참조하십시오. Curl IN PHP

관련 문제