0

Possible Duplicate:
get the value of an url response with curl

I have an php page names stores.php now i want to see the output of this page using curl, what i can do ? my code is so far for stores.php page

<?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;
}

?>
Community
  • 1
  • 1
John
  • 329
  • 1
  • 4
  • 18
  • in what environment (os, ...) you want to use curl to show the response of your script? – scube Dec 05 '11 at 09:29
  • Duplicate? http://stackoverflow.com/q/2001897/508702 – Bas Slagter Dec 05 '11 at 09:35
  • @root: You want to use the curl library of ubunto directly on bash not through php, right? – scube Dec 05 '11 at 09:44
  • @scube:) right now i install curl library in ubuntu through terminal, i do not no more about curl, but i want to display my page result by using this curl or nothing else after following this link http://www.blog.highub.com/php/php-core/linux-ubuntu-install-setup-php-curl/ – John Dec 05 '11 at 09:49

2 Answers2

2

use man curl for how to use curl to display the response of a webpage.

example:

curl "http://www.stackoverflow.com"
scube
  • 1,931
  • 15
  • 21
  • :) Exactly I want to display the response of a webpage but hows in my case ?I know some basic commands, this command also but how can i implement such commands in my case – John Dec 05 '11 at 09:59
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
    }  

// $proxy is optional // if you want to open target url through a proxy use it like this

    $proxy = "120.232.23.23:8080";
    $result = getPage($url, $referer, $agent, $header, $timeout,$proxy);
CoreCoder
  • 389
  • 1
  • 4
  • 14