But I figured I'd post it here anyway.
So what do I have this time? Well I was inspired by
this snippet on phpfreaks.com and the
FTP class here and so I decided to remake the curl class for PHP 5. That and I really had nothing else to do.
CODE
<?php
class curl {
public $curlHandle;
public function __construct($url) {
if(!function_exists('curl_init')) {
throw new Exception('You must have Curl compiled or installed for this class to work.');
}
if($this->curlHandle = curl_init($url)) {
return 1;
} else {
return 0;
}
}
public function __call($func, $args = array()) {
array_unshift($args, $this->curlHandle);
return call_user_func_array('curl_'.$func, $args);
}
public function post($arr, $force = FALSE) {
if(!is_array($arr)) {
throw new Exception('$arr must be an array!');
}
$rtn['CURLOPT_POST'] = curl_setopt($this->curlHandle, CURLOPT_POST, 1);
$rtn['CURLOPT_POSTFIELDS'] = curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, http_build_query($arr));
return $rtn;
}
/*
Still working on this one.
public function get($arr) {
if(!is_array($arr)) {
throw new Exception('$arr must be an array!');
}
}*/
public function __destruct() {
@curl_close($this->curlHandle);
}
}
?>
example
CODE
<?php
include_once('class.curl.php');
try {
$c = new curl('http://someurl.com');
$array = array(
'username' => 'Mikey',
'password' => md5('password'),
'loginTime' => time()
);
//The short way.
$c->post($array);
//The long way.
$c->setopt(CURLOPT_POST, 1);
$c->setopt(CURLOPT_POSTFIELDS, http_build_query($arr));
$c->exec();
} catch(Expection $c) {
print_r($c);
}
?>
I'm thinking of adding some more 'maco' methods like curl::post(), but I'm not to sure. I'll have to play around with this some more.