http://meami.org = operating systems
=-4846160535372056422101058856413604372167096354723597262791175876179524627 7798557
093872360971642634975025223136356223006759983984746841816170866885980311522 76727
Zl)) {
logToFile("reply.txt", $hname.": ".$val);
if($header_name == "set-cookie") {
header($hname.": ".$val, false);
} else {
header($hname.": ".$val, true);
}
} else {
if($header_name == 'content-length') {
header("$hname: 0", true);
logToFile("reply.txt", "$hname: 0");
} else {
logToFile("reply.txt", $header_name);
header($header_name, true);
}
}
}
}
} /*else {
if($header_name != 'transfer-encoding' && $header_name != 'x-
powered-by' && $header_name != 'connection' && $header_name != 'keep-
alive') {
if(!empty($headers[$header_name])) {
logToFile("reply.txt", $header_name.": ".$headers
[$header_name]);
header($header_name.": ".$headers[$header_name], true);
} else {
logToFile("reply.txt", $header_name);
header($header_name, true);
}
}
}*/
}
logToFile("reply.txt", "-----------------");
for(;;) {
$error=$http->ReadReplyBody($body,1000);
if($error!="" || strlen($body)==0)
break;
echo $body;
flush();
}
}
l)) {
logToFile("reply.txt", $hname.": ".$val);
if($header_name == "set-cookie") {
header($hname.": ".$val, false);
} else {
header($hname.": ".$val, true);
}
} else {
if($header_name == 'content-length') {
header("$hname: 0", true);
logToFile("reply.txt", "$hname: 0");
} else {
logToFile("reply.txt", $header_name);
header($header_name, true);
}
}
}
}
} /*else {
if($header_name != 'transfer-encoding' && $header_name != 'x-
powered-by' && $header_name != 'connection' && $header_name != 'keep-
alive') {
if(!empty($headers[$header_name])) {
logToFile("reply.txt", $header_name.": ".$headers
[$header_name]);
header($header_name.": ".$headers[$header_name], true);
} else {
logToFile("reply.txt", $header_name);
header($header_name, true);
}
}
}*/
}
logToFile("reply.txt", "-----------------");
for(;;) {
$error=$http->ReadReplyBody($body,1000);
if($error!="" || strlen($body)==0)
break;
echo $body;
flush();
}
}
/*$http->SaveCookies($site_cookies);
if(!empty($site_cookies)) {
@file_put_contents("cook.dat", serialize($site_cookies));
}*/
$http->Close();
}
if(strlen($error))
echo "<CENTER><H2>Error: ",$error,"</H2><CENTER>\n";
exit(0);
#####################################################
function cookieEncode($str) {
return str_replace(array(' ',
"\t",
';',
','),
array('%20',
'%09',
'%3B',
'%2C'),
$str);
}
function cookieDecode($str) {
return str_replace(array('%20',
'%09',
'%3B',
'%2C'),
array(' ',
"\t",
';',
','),
$str);
}
function cenc2() {
$qs = "";
if (@sizeof(array_values($_COOKIE)) > 0) {
foreach ($_COOKIE as $key => $val) {
if (is_array($val) || is_object($val)) {
$qs .= "$key=" . rawurlencode(serialize($val)) + "; ";
} else {
//if(preg_match("/\\;|\\=/", $val)) $val = rawurlencode($val);
//$val = cenc($val, 0);
$key = cookieEncode($key);
$val = cookieEncode($val);
$qs .= "$key=$val; ";
}
}
}
$qs = rtrim($qs, "; ");
return $qs;
}
function set_post_vars($array, $parent_key = null) {
$temp = array();
foreach ($array as $key => $value) {
$key = isset($parent_key) ? sprintf('%s[%s]', $parent_key,
($key)) : ($key);
if (is_array($value)) {
$temp = array_merge($temp, set_post_vars($value, $key));
} else {
$temp[$key] = ($value);
}
}
return $temp;
}
function logToFile($filename, $msg) {
if(!$DEBUG) return;
// open file
$fd = fopen($filename, "a");
// append date/time to message
$str = "[" . date("Y/m/d h:i:s", mktime()) . "] " . $msg;
// write string
fwrite($fd, $str . "\n");
// close file
fclose($fd);
}
class http_class
{
var $host_name="";
var $host_port=0;
var $proxy_host_name="";
var $proxy_host_port=80;
var $socks_host_name = '';
var $socks_host_port = 1080;
var $protocol="http";
var $request_method="GET";
var $user_agent='httpclient';
var $authentication_mechanism="";
var $user;
var $password;
var $realm;
var $workstation;
var $proxy_authentication_mechanism="";
var $proxy_user;
var $proxy_password;
var $proxy_realm;
var $proxy_workstation;
var $request_uri="";
var $request="";
var $request_headers=array();
var $request_user;
var $request_password;
var $request_realm;
var $request_workstation;
var $proxy_request_user;
var $proxy_request_password;
var $proxy_request_realm;
var $proxy_request_workstation;
var $request_body="";
var $request_arguments=array();
var $protocol_version="1.1";
var $timeout=0;
var $data_timeout=0;
var $debug=0;
var $debug_response_body=1;
var $html_debug=0;
var $support_cookies=1;
var $cookies=array();
var $error="";
var $exclude_address="";
var $follow_redirect=0;
var $redirection_limit=5;
var $response_status="";
var $response_message="";
var $file_buffer_length=8000;
var $force_multipart_form_post=0;
var $prefer_curl = 0;
/* public variables - PLEASE ACCESS */
var $state="Disconnected";
var $use_curl=0;
var $connection=0;
var $content_length=0;
var $response="";
var $read_response=0;
var $read_length=0;
var $request_host="";
var $next_token="";
var $redirection_level=0;
var $chunked=0;
var $remaining_chunk=0;
var $last_chunk_read=0;
var $months=array(
"Jan"=>"01",
"Feb"=>"02",
"Mar"=>"03",
"Apr"=>"04",
"May"=>"05",
"Jun"=>"06",
"Jul"=>"07",
"Aug"=>"08",
"Sep"=>"09",
"Oct"=>"10",
"Nov"=>"11",
"Dec"=>"12");
var $session='';
var $connection_close=0;
/* PUBLIC methods _ PLEASE CALL */
Function Tokenize($string,$separator="")
{
if(!strcmp($separator,""))
{
$separator=$string;
$string=$this->next_token;
}
for($character=0;$character<strlen($separator);$character++)
{
if(GetType($position=strpos($string,$separator[$character]))
=="integer")
$found=(IsSet($found) ? min($found,$position) : $position);
}
if(IsSet($found))
{
$this->next_token=substr($string,$found+1);
return(substr($string,0,$found));
}
else
{
$this->next_token="";
return($string);
}
}
Function CookieEncode($value, $name)
{
return($name ? str_replace("=", "%25", $value) : str_replace(";",
"%3B", $value));
}
Function SetError($error)
{
return($this->error=$error);
}
Function SetPHPError($error, &$php_error_message)
{
if(IsSet($php_error_message)
&& strlen($php_error_message))
$error.=": ".$php_error_message;
return($this->SetError($error));
}
Function SetDataAccessError($error,$check_connection=0)
{
$this->error=$error;
if(!$this->use_curl
&& function_exists("socket_get_status"))
{
$status=socket_get_status($this->connection);
if($status["timed_out"])
$this->error.=": data access time out";
elseif($status["eof"])
{
if($check_connection)
$this->error="";
else
$this->error.=": the server disconnected";
}
}
}
Function OutputDebug($message)
{
$message.="\n";
if($this->html_debug)
$message=str_replace("\n","<br />\n",HtmlEntities($message));
echo $message;
flush();
}
Function GetLine()
{
for($line="";;)
{
if($this->use_curl)
{
$eol=strpos($this->response,"\n",$this->read_response);
$data=($eol ? substr($this->response,$this->read_response,$eol
+1-$this->read_response) : "");
$this->read_response+=strlen($data);
}
else
{
if(feof($this->connection))
{
$this->SetDataAccessError("reached the end of data while
reading from the HTTP server connection");
return(0);
}
$data=fgets($this->connection,100);
}
if(GetType($data)!="string"
|| strlen($data)==0)
{
$this->SetDataAccessError("it was not possible to read line
from the HTTP server");
return(0);
}
$line.=$data;
$length=strlen($line);
if($length
&& !strcmp(substr($line,$length-1,1),"\n"))
{
$length-=(($length>=2 && !strcmp(substr($line,
$length-2,1),"\r")) ? 2 : 1);
$line=substr($line,0,$length);
if($this->debug)
$this->OutputDebug("S $line");
return($line);
}
}
}
Function PutLine($line)
{
if($this->debug)
$this->OutputDebug("C $line");
if(!fputs($this->connection,$line."\r\n"))
{
$this->SetDataAccessError("it was not possible to send a line to
the HTTP server");
return(0);
}
return(1);
}
Function PutData(&$data)
{
if(strlen($data))
{
if($this->debug)
$this->OutputDebug("C $data");
if(!fputs($this->connection,$data))
{
$this->SetDataAccessError("it was not possible to send data to
the HTTP server");
return(0);
}
}
return(1);
}
Function FlushData()
{
if(!fflush($this->connection))
{
$this->SetDataAccessError("it was not possible to send data to
the HTTP server");
return(0);
}
...
leer más »