note 98628 added to function.curl-exec
| From: | DavidfromCode2Design dot com at osu1 dot php dot net | Date: | Mon, 28 Jun 2010 02:44:18 +0000 |
| Subject: | note 98628 added to function.curl-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170510@lists.php.net to get a copy of this message | ||
Just in case anyone is looking for a a couple of simple functions I thought I'd post these.
<?php
/**
* Send a POST requst using cURL
* @param string $url to request
* @param array $post values to send
* @param array $options for cURL
* @return string
*/
function curl_post($url, array $post = NULL, array $options = array())
{
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
/**
* Send a GET requst using cURL
* @param string $url to request
* @param array $get values to send
* @param array $options for cURL
* @return string
*/
function curl_get($url, array $get = NULL, array $options = array())
{
$defaults = array(
CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : '').
http_build_query($get),
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 4
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 208.101.220.138
----
Manual Page -- http://www.php.net/manual/en/function.curl-exec.php
Edit -- https://master.php.net/note/edit/98628
Del: integrated -- https://master.php.net/note/delete/98628/integrated
Del: useless -- https://master.php.net/note/delete/98628/useless
Del: bad code -- https://master.php.net/note/delete/98628/bad+code
Del: spam -- https://master.php.net/note/delete/98628/spam
Del: non-english -- https://master.php.net/note/delete/98628/non-english
Del: in docs -- https://master.php.net/note/delete/98628/in+docs
Del: other reasons-- https://master.php.net/note/delete/98628
Reject -- https://master.php.net/note/reject/98628
Search -- https://master.php.net/manage/user-notes.php