note 92590 deleted from book.curl by danbrown

From: Date: Mon, 03 Aug 2009 17:04:19 +0000
Subject: note 92590 deleted from book.curl by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-159051@lists.php.net to get a copy of this message
Note Submitter: martin at aarhof dot eu ---- <?php class cURL { private $session; private $options; private $posts = array(); public function __construct($url, $timeout = 10) { if (! function_exists('curl_init')) { trigger_error('CURL is not installed', E_USER_ERROR); } $this->CURLOPT_AUTOREFERER = true; $this->CURLOPT_TIMEOUT = $timeout; $this->CURLOPT_URL = $url; } public function setOptions($key, $value) { $key = (defined($key) ? constant($key) : $key); $this->options[$key] = $value; } public function __set($key, $value) { $this->setOptions($key, $value); } public function setPost($key, $value) { $this->posts[$key] = $value; } public function setPostArray(array $array) { foreach($array AS $key => $val) { $this->setPost($key, $val); } } public function exec($return = true) { $handle = curl_init(); if ($return === true) $this->CURLOPT_RETURNTRANSFER = 1; if ($this->posts) { $this->CURLOPT_POST = 1; $this->CURLOPT_POSTFIELDS = $this->posts; } foreach ($this->options AS $key => $value) { if (! curl_setopt($handle, $key, $value)) { trigger_error('<b>curl_setopt</b> could not set <b>' . $key . '</b> with value <b>' . $value, E_USER_ERROR); } } $content = curl_exec($handle); $header = curl_getinfo($handle); $error = curl_error($handle); $errno = curl_errno($handle); curl_close($handle); return array( 'response' => $content, 'header' => $header, 'error' => $error, 'errno' => $errno ); } }

« previous php.notes (#159051) next »