I hope you can help me, I am using this class which I got from phpclasses.com. I have a slight problem with it though as I am using the POST method to send form data to a page on another site and get the result. The result I get is always truncated (and it is always in 1 of 2 places!) I would like to see the whole of the file. Thanks
the class:
PHP Code:
<?php
/**************************************************************************************************
* Class: Advanced HTTP Client
***************************************************************************************************
* Version : 1.1
* Released : 06-20-2002
* Last Modified : 06-10-2003
* Author : GuinuX <guinux@cosmoplazza.com>
*
***************************************************************************************************
* Changes
***************************************************************************************************
* 2003-06-10 : GuinuX
* - Fixed a bug with multiple gets and basic auth
* - Added support for Basic proxy Authentification
* 2003-05-25: By Michael Mauch <michael.mauch@gmx.de>
* - Fixed two occurences of the former "status" member which is now deprecated
* 2002-09-23: GuinuX
* - Fixed a bug to the post method with some HTTP servers
* - Thanx to l0rd jenci <lord_jenci@bigfoot.com> for reporting this bug.
* 2002-09-07: Dirk Fokken <fokken@cross-consulting.com>
* - Deleted trailing characters at the end of the file, right after the php closing tag, in order
* to fix a bug with binary requests.
* 2002-20-06: GuinuX, Major changes
* - Turned to a more OOP style => added class http_header, http_response_header,
* http_request_message, http_response_message.
* The members : status, body, response_headers, cookies, _request_headers of the http class
* are Deprecated.
* 2002-19-06: GuinuX, fixed some bugs in the http::_get_response() method
* 2002-18-06: By Mate Jovic <jovic@matoma.de>
* - Added support for Basic Authentification
* usage: $http_client = new http( HTTP_V11, false, Array('user','pass') );
*
***************************************************************************************************
* Description:
***************************************************************************************************
* A HTTP client class
* Supports :
* - GET, HEAD and POST methods
* - Http cookies
* - multipart/form-data AND application/x-www-form-urlencoded
* - Chunked Transfer-Encoding
* - HTTP 1.0 and 1.1 protocols
* - Keep-Alive Connections
* - Proxy
* - Basic WWW-Authentification and Proxy-Authentification
*
***************************************************************************************************
* TODO :
***************************************************************************************************
* - Read trailing headers for Chunked Transfer-Encoding
***************************************************************************************************
* usage
***************************************************************************************************
* See example scripts.
*
***************************************************************************************************
* License
***************************************************************************************************
* GNU Lesser General Public License (LGPL)
* http://www.opensource.org/licenses/lgpl-license.html
*
* For any suggestions or bug report please contact me : guinux@cosmoplazza.com
***************************************************************************************************/
/******************************************************************************************
* class http_header
******************************************************************************************/
class http_header {
var $_headers;
var $_debug;
function http_header() {
$this->_headers = Array();
$this->_debug = '';
} // End Of function http_header()
function get_header( $header_name ) {
$header_name = $this->_format_header_name( $header_name );
if (isset($this->_headers[$header_name]))
return $this->_headers[$header_name];
else
return null;
} // End of function get()
function set_header( $header_name, $value ) {
if ($value != '') {
$header_name = $this->_format_header_name( $header_name );
$this->_headers[$header_name] = $value;
}
} // End of function set()
function reset() {
if ( count( $this->_headers ) > 0 ) $this->_headers = array();
$this->_debug .= "\n--------------- RESETED ---------------\n";
} // End of function clear()
function serialize_headers() {
$str = '';
foreach ( $this->_headers as $name=>$value) {
$str .= "$name: $value" . HTTP_CRLF;
}
return $str;
} // End of function serialize_headers()
function add_debug_info( $data ) {
$this->_debug .= $data;
}
function get_debug_info() {
return $this->_debug;
}
} // End Of Class http_header
/******************************************************************************************
* class http_response_header
******************************************************************************************/
class http_response_header extends http_header {
var $cookies_headers;
function http_response_header() {
$this->cookies_headers = array();
http_header::http_header();
} // End of function http_response_header()
function reset() {
if ( count( $this->cookies_headers ) > 0 ) $this->cookies_headers = array();
http_header::reset();
}
} // End of class http_response_header
/******************************************************************************************
* class http_request_message
******************************************************************************************/
class http_request_message extends http_header {
var $body;
function http_request_message() {
$this->body = '';
http_header::http_header();
} // End of function http_message()
function reset() {
$this->body = '';
http_header::reset();
}
}
/******************************************************************************************
* class http_response_message
******************************************************************************************/
class http_response_message extends http_response_header {
var $body;
var $cookies;
function http_response_message() {
$this->cookies = new http_cookie();
$this->body = '';
http_response_header::http_response_header();
} // End of function http_response_message()
function get_status() {
if ( $this->get_header( 'Status' ) != null )
return (integer)$this->get_header( 'Status' );
else
return -1;
}
function get_protocol_version() {
if ( $this->get_header( 'Protocol-Version' ) != null )
return $this->get_header( 'Protocol-Version' );
else
return HTTP_V10;
}
function get_content_type() {
$this->get_header( 'Content-Type' );
}
function get_body() {
return $this->body;
}
function reset() {
$this->body = '';
http_response_header::reset();
}
/******************************************************************************************
* class http_cookie
******************************************************************************************/
class http_cookie {
var $cookies;
function http_cookie() {
$this->cookies = array();
} // End of function http_cookies()
function _now() {
return strtotime( gmdate( "l, d-F-Y H:i:s", time() ) );
} // End of function _now()
function _timestamp( $date ) {
if ( $date == '' ) return $this->_now()+3600;
$time = strtotime( $date );
return ($time>0?$time:$this->_now()+3600);
} // End of function _timestamp()
if ($sep_pos){
$name = substr( $value_str, 0, $sep_pos );
$value = substr( $value_str, $sep_pos+1 );
$this->set( $name, $value, $domain, $path, $expires );
}
} // End of function parse()
} // End of class http_cookie
/******************************************************************************************
* class http
******************************************************************************************/
class http {
var $_socket;
var $host;
var $port;
var $http_version;
var $user_agent;
var $errstr;
var $connected;
var $uri;
var $_proxy_host;
var $_proxy_port;
var $_proxy_login;
var $_proxy_pwd;
var $_use_proxy;
var $_auth_login;
var $_auth_pwd;
var $_response;
var $_request;
var $_keep_alive;
return $this->_response->get_status();
} // End of function post_xml()
function disconnect() {
if ($this->_socket && $this->connected) {
fclose($this->_socket);
$this->connected = false;
}
} // End of function disconnect()
would it be possible to show us an example of the output, or a link to your web page?
at first sight, nothing is wrong with your code. it could be your server, my friend had a problem like you have: his php pages where always displayed partially. especcially when it where rather cpu intensive pages. he solved the problem by reinstalling apache and php
Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks