2011-12-05 6 views
0

가능한 중복 :
get the value of an url response with curlPHP에서 컬을 사용하는 방법?

지금 내가 컬을 사용하여이 페이지의 출력을보고 싶어 stores.php PHP 페이지 이름, 내가 무엇을 할 수 있나요? 내 코드는

<?php 


include_once '../application/Boot.php'; 


if ($_SERVER['REQUEST_METHOD'] == 'POST') { 
    $body = @file_get_contents('php://input'); 
    $json = json_decode($body, true); 


    if (isset($json['version'])) { 
     $client_cache_version = @$json['version']; 

     $sql = $db->quoteInto("SELECT * FROM stores where version_modified > ". $client_cache_version); 
     $results = $db->fetchAll($sql); 


     $version_sql = $db->quoteInto("SELECT max(version_modified) as version FROM stores"); 
     $version_results = $db->fetchAll($version_sql); 

     $count = array(
      'count' => sizeof($results) 
     ); 

     array_push($results, $version_results['0']); 

     array_push($results, $count); 
     //ob_start("ob_gzhandler"); 

     header('HTTP/1.1 200 Stores list'); 
     echo json_encode($results); 
     exit; 

    }else { 


     header('HTTP/1.1 400 Bad Request'); 

     exit; 
    } 

}else{ 


    header('HTTP/1.1 400 Bad Request'); 
    exit; 
} 

?> 
+0

다음과 같이 사용할 프록시를 통해 대상 URL을 열려면 , ...) 스크립트의 응답을 보여주기 위해 컬 (curl)을 사용하고 싶습니까? – scube

+0

중복? http://stackoverflow.com/q/2001897/508702 –

+0

@scube :) os is linux (우분투) – John

답변

2

stores.php 페이지에 대한 지금까지 웹 페이지의 응답을 표시 컬 사용하는 방법에 대한 사용 man curl입니다.

예 :

curl "http://www.stackoverflow.com" 
+0

:) 정확하게 웹 페이지의 응답을 표시하고 싶지만 내 경우에는 의미가 있습니까? 몇 가지 기본 명령을 알고 있습니다. 또한 내 경우에는 그런 명령을 어떻게 구현할 수 있습니까? – John

0
function getPage($url, $referer, $agent, $header, $timeout, $proxy="") 
    { 

     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_HEADER, $header); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     if($proxy != "") 
     { 
     curl_setopt($ch, CURLOPT_PROXY, $proxy); 
     curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0); 
     } 
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
     curl_setopt($ch, CURLOPT_REFERER, $referer); 
     curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
     curl_setopt($ch, CURLOPT_COOKIEJAR, realpath('cookies.txt')); 
     curl_setopt($ch, CURLOPT_COOKIEFILE, realpath('/cookies.txt')); 
     $result['EXE'] = curl_exec($ch); 
     $result['INF'] = curl_getinfo($ch); 
     $result['ERR'] = curl_error($ch); 

     curl_close($ch); 

     return $result; 
    } 

    $url = "www.targeturl.com"; 
    $referer = "http;//www.google.com"; 
    $agent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; 
    $header = 1; 
    $timeout = 15; 


    $result = getPage($url, $referer, $agent, $header, $timeout); 

    //$result["ERR"] contain errors if any one 
    //$result['EXE'] have the html of traget url you supplied in $url variable 
    //$result['info] have information. 

    you can use it like this 

    if(empty($result["ERR"])) // no error 
    { 
    echo $result['EXE']; //html of target url 
    } 
    else // errors 
    { 
     // do something on errors 
    } 

// $ 프록시는 선택 사항입니다 // 당신은 (OS 어떤 환경에서이

$proxy = "120.232.23.23:8080"; 
    $result = getPage($url, $referer, $agent, $header, $timeout,$proxy); 
관련 문제