Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,461 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,371 people online right now. Registration is fast and FREE... Join Now!




Wip, Not Quite Ready Yet

 
Reply to this topicStart new topic

Wip, Not Quite Ready Yet

snoj
post 12 Mar, 2005 - 02:22 AM
Post #1


$Null

Group Icon
Joined: 31 Mar, 2003
Posts: 3,304



Thanked 5 times

Dream Kudos: 700
My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

cyberscribe
post 13 Mar, 2005 - 12:56 AM
Post #2


humble.genius

Group Icon
Joined: 5 May, 2002
Posts: 1,062



Thanked 2 times

Dream Kudos: 154
My Contributions


What PHP really needs is something like CPAN's WWW::Mechanize::FormFiller to handle automatic testing of complex web forms. Ideally it would extend the Pear HTTP_Request class or something similar.

So ... if you have nothing else to do ... wink2.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 12:34PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month