note 68122 added to function.curl-setopt
| From: | bendavis78 at gmail dot com | Date: | Thu, 13 Jul 2006 22:58:19 +0000 |
| Subject: | note 68122 added to function.curl-setopt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-114766@lists.php.net to get a copy of this message | ||
You can use CURLOPT_HEADERFUNCTION with a callback inside an object. This makes is it easy to
capture the headers for later use. For example:
<?
class Test
{
public $headers;
//...
public function exec($opts)
{
$this->headers = array();
$opts[CURLOPT_HEADERFUNCTION] = array($this, '_setHeader');
$ch = curl_init();
curl_setopt_array($ch, $opts);
return curl_exec($ch);
}
private function _setHeader($ch, $header)
{
$this->headers[] = $header;
return strlen($header);
}
}
$test = new Test();
$opts = array(
//... your curl opts here
);
$data = $test->exec($opts);
print_r($test->headers);
?>
...something like that
(This works in php v. 5.1.4)
----
Server IP: 216.194.113.175
Probable Submitter: 69.15.248.2
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.curl-setopt.php
Edit -- http://master.php.net/note/edit/68122
Del: integrated -- http://master.php.net/note/delete/68122/integrated
Del: useless -- http://master.php.net/note/delete/68122/useless
Del: bad code -- http://master.php.net/note/delete/68122/bad+code
Del: spam -- http://master.php.net/note/delete/68122/spam
Del: non-english -- http://master.php.net/note/delete/68122/non-english
Del: in docs -- http://master.php.net/note/delete/68122/in+docs
Del: other reasons-- http://master.php.net/note/delete/68122
Reject -- http://master.php.net/note/reject/68122
Search -- http://master.php.net/manage/user-notes.php