I try to communicate with a server,
i think it is bettet to write a class for this task.
If I read the class variable, there are no values.
but in the debuge mode i can see the correct values.
thanks for help
here the code:
Code: Select all
<?php
class CurlReader {
var $body;
var $headers;
var $c;
function CurlReader() {
$iheaders[]= "Content-Type: text/xml";
$iheaders[]= "Pragma: no-cache";
$this->c = curl_init();
curl_setopt($this->c, CURLOPT_HEADER, 1);
curl_setopt($this->c, CURLOPT_SSL_VERIFYPEER, "false");
curl_setopt($this->c, CURLOPT_HTTPHEADER, $iheaders);
curl_setopt($this->c, CURLOPT_POST, 1);
curl_setopt($this->c, CURLOPT_POSTFIELDS, 'etwas');
curl_setopt($this->c, CURLOPT_HEADERFUNCTION, array($this,'parseHeader'));
curl_setopt($this->c, CURLOPT_WRITEFUNCTION, array($this, 'parseBody'));
}
function parseHeader($curl, $data)
{
list($header, $value) = explode(': ', $data, 2);
$this->headers[$header] = value;
}
}
function parseBody($curl, $data)
{
$this->body .= $data;
}
function get($url) {
$this->headers = array();
$this->body = '';
curl_setopt($this->c, CURLOPT_URL, $url);
return curl_exec($this->c);
}
function close()
{
curl_close($this->c);
}
function getbody()
{
return $this->body;
}
}
$c->get('https://www.server.de);
print $c->getbody();
$erg= $c->getbody();
$c->close();
?>