Login   Register  
PHP Classes
elePHPant
Icontem

File: README

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Helmut Daschnigrum  >  HTTP Retriever  >  README  >  Download  
File: README
Role: Documentation
Content type: text/plain
Description: Documentation
Class: HTTP Retriever
HTTP client to access Web servers
Author: By
Last change:
Date: 2006-05-15 17:11
Size: 3,860 bytes
 

Contents

Class file image Download
HTTP Retriever
Version v1.1.7
Copyright 2004-2006, Steve Blinch
http://code.blitzaffe.com
============================================================================

DESCRIPTION

Provides a pure-PHP implementation of an HTTP v1.1 client, including support
for chunked transfer encoding and user agent spoofing.  Both GET and POST
requests are supported.

This can be used in place of something like CURL or WGET for HTTP requests.
Native SSL (HTTPS) requests are also supported if the OpenSSL extension is
installed under PHP v4.3.0 or greater.

If native SSL support is not available, the class will also check for the
CURL extension; if it's installed, it will transparently be used for SSL
(HTTPS) requests.

If neither native SSL support nor the CURL extension are available, and
libcurlemu (a CURL emulation library available from our web site) is found,
the class will also check for the CURL console binary (usually in
/usr/bin/curl); if it's installed, it will transparently be used for SSL
requests.

In short, if it's possible to make an HTTP/HTTPS request from your server,
this class can most likely do it.


HISTORY

1.1.7 (18-Apr-2006)
- Added support for automatically following HTTP redirects
- Added ::get_error() method to get any available error message (be
it an HTTP result error or an internal/connection error)
- Added ::cache_hit variable to determine whether the page was cached

1.1.6 (04-Mar-2006)
- Added stream_timeout class variable.
- Added progress_callback class variable.
- Added support for braindead servers that ignore Connection: close


EXAMPLE

// HTTPRetriever usage example
require_once("class_HTTPRetriever.php");
$http = &new HTTPRetriever();


// Example GET request:
// ----------------------------------------------------------------------------
$keyword = "blitzaffe code"; // search Google for this keyword
if (!$http->get("http://www.google.com/search?hl=en&q=%22".urlencode($keyword)."%22&btnG=Search&meta=")) {
echo "HTTP request error: #{$http->result_code}: {$http->result_text}";
return false;
}
echo "HTTP response headers:<br><pre>";
var_dump($http->response_headers);
echo "</pre><br>";

echo "Page content:<br><pre>";
echo $http->response;
echo "</pre>";
// ----------------------------------------------------------------------------


// Example POST request:
// ----------------------------------------------------------------------------
$keyword = "blitzaffe code"; // search Google for this keyword
$values = array(
"hl"=>"en",
"q"=>"%22".urlencode($keyword)."%22",
"btnG"=>"Search",
"meta"=>""
);
// Note: This example is just to demonstrate the POST equivalent of the GET
// example above; running this script will return a 501 Not Implemented, as
// Google does not support POST requests.
if (!$http->post("http://www.google.com/search",$http->make_query_string($values))) {
echo "HTTP request error: #{$http->result_code}: {$http->result_text}";
return false;
}
echo "HTTP response headers:<br><pre>";
var_dump($http->response_headers);
echo "</pre><br>";

echo "Page content:<br><pre>";
echo $http->response;
echo "</pre>";
// ----------------------------------------------------------------------------


LICENSE

This script is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This script is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
details.

You should have received a copy of the GNU General Public License along
with this script; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA  02111-1307  USA