Yii 1.1: curl

You can use it for geting data from other websites via CURL
44 followers

CURL for Yii

Requirements

...requirements of using this extension (e.g. Yii 1.1 or above)... ..You must have CURL enabled in order to use this extension...

Usage

  1. You have to download and upload files to /protected/extensions/curl/.
  2. Include extension in config/main.php

BASIC IMPLEMENTATION

'CURL' =>array(
   'class' => 'application.extensions.curl.Curl',
)

ADVANCED IMPLEMENTATION

'curl' => array(
    'class' => 'application.extensions.curl.Curl',
    'options'=>array(
        'timeout'=>0,
 
        'cookie'=>array(
            'set'=>'cookie'
        ),
 
        'login'=>array(
            'username'=>'myuser',
            'password'=>'mypass'
        ),
 
        'proxy'=>array(
            'url'=>'someproxy.com',
            'port'=>80
        ),
 
        'proxylogin'=>array(
            'username'=>'someuser',
            'password'=>'somepasswords'
        ),
 
        'setOptions'=>array(
             CURLOPT_UPLOAD => true,
             CURLOPT_USERAGENT => Yii::app()->params['agent']
        ),
    )
),

GET EXAMPLES

$run_one = Yii::app()->curl->run('http://maps.google.com/maps/geo?q=zagreb&output=json&key=ABQIAAAAR3YzPp1SL-w7k-Nhadw6oRRSU9EEwCG8ydw3m56rm2GtI8BohRSHN1qNuRyOrnYS_BNY1_2RnyuYTA');
 
 
if(!$run_one->hasErrors()) {
 
    echo '<pre>';
        print_r(json_decode($run_one->getData()));
    echo '</pre>';
    echo $run_one->getInfo();
 
} else {
    echo '<pre>';
    var_dump($run_one->getErrors());
    echo '</pre>';
}
$run_two = Yii::app()->curl->run('http://www.google.com/ig/calculator?q=100EUR=?HRK');
 
if(!$run_two->hasErrors()) {
 
    echo '<pre>';
    print_r(json_decode($run_two->getData()));
    echo '</pre>';
    echo $run_two->getInfo();
 
} else {
    echo '<pre>';
    var_dump($run_two->getErrors());
    echo '</pre>';
}

Total 14 comments

#14852 report it
Igor Ivanovic at 2013/09/14 04:51pm
@Davuz Remove header from request

CURLOPT_HEADER -> false

#13457 report it
Davuz at 2013/05/29 02:06pm
How to get raw html?

after I run $result = $run_two->getData(); I see in result has Http header info + html. I want only html in result, please? How do?

#12377 report it
Nur Rochim at 2013/03/17 10:11am
Demo

Demo please...

#11093 report it
Edgar at 2012/12/16 07:48am
HTTPS certificated connection

hi, how to add .cert and .key files to connection?

#10051 report it
Deepak Pradhan at 2012/10/02 06:15am
Simple and elegant

Thanks a lot

#8203 report it
Davey at 2012/05/17 09:39am
Line 179

There is missing a 'N' on line 179 at "CURLOPT_FOLLOWLOCATIO".

Good extension though!

#6218 report it
jowee at 2011/12/20 01:33am
need small fix

I receive an error

curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set (/home/seopm/www/protected/extensions/curl/Curl.php:94)

There is the fix of same issue for osCommerce, it can be useful for you.

#6073 report it
Chris83 at 2011/12/09 09:00pm
There are other types besides GET and POST

It would probably be wiser to use a string or constant for the request type. I cannot help it but I hate booleans parameters and if you've worked with payment gateway integration you know why. :) Good job with the extension, nevertheless.

#3396 report it
Igor Ivanovic at 2011/04/09 06:14pm
GET paramter default is TRUE

If you set to false your request become POST request.

#3395 report it
echo66 at 2011/04/09 12:46pm
One question

What is the purposue of the boolean GET parameter, in the run function header?

#2871 report it
Seal at 2011/02/18 08:38pm
Nice

Thank you...great job!

#2398 report it
Tipugin at 2010/12/23 08:27am
cool!

useful! thx!

#2393 report it
Luis Lobo Borobia at 2010/12/22 07:13pm
Love it!

I was just about to write one for this :) Thakns!

#2363 report it
Maurizio Domba Cerin at 2010/12/17 04:08am
Nice job

Nice extension, useful too...

Leave a comment

Please to leave your comment.

Create extension
Downloads