note 92590 added to book.curl
| From: | martinataarhofdoteu at osu1 dot php dot net | Date: | Thu, 30 Jul 2009 16:01:18 +0000 |
| Subject: | note 92590 added to book.curl | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158921@lists.php.net to get a copy of this message | ||
<?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
);
}
}
----
Server IP: 195.184.96.15
Probable Submitter: 91.143.115.126
----
Manual Page -- http://www.php.net/manual/en/book.curl.php
Edit -- https://master.php.net/note/edit/92590
Del: integrated -- https://master.php.net/note/delete/92590/integrated
Del: useless -- https://master.php.net/note/delete/92590/useless
Del: bad code -- https://master.php.net/note/delete/92590/bad+code
Del: spam -- https://master.php.net/note/delete/92590/spam
Del: non-english -- https://master.php.net/note/delete/92590/non-english
Del: in docs -- https://master.php.net/note/delete/92590/in+docs
Del: other reasons-- https://master.php.net/note/delete/92590
Reject -- https://master.php.net/note/reject/92590
Search -- https://master.php.net/manage/user-notes.php