cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Passing Username and Password via PHP into curl - Suggestions

From: Tim Tessier <ttessier_at_swhistlesoft.com>
Date: Wed, 10 Aug 2011 16:55:18 -0400

Additional Note:

from:
http://www.php.net/manual/en/curl.examples-basic.php

basic curl example

*$ch **= curl_init("http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);**
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($ch);
curl_close($ch);
*
from:
http://www.php.net/manual/en/function.curl-setopt.php

*CURLOPT_POSTFIELDS* The full data to post in a HTTP "POST" operation. To
post a file, prepend a filename with *@* and use the full path. The filetype
can be explicitly specified by following the filename with the type in the
format '*;type=mimetype*'. This parameter can either be passed as a
urlencoded string like '*para1=val1&para2=val2&...*' or as an array with the
field name as key and field data as value. If *value* is an array, the *
Content-Type* header will be set to *multipart/form-data*. As of PHP 5.2.0,
files thats passed to this option with the *@* prefix must be in array form
to work.

from:
http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_URL, _VIRUS_SCAN_URL);
    curl_setopt($ch, CURLOPT_POST, true);
    // same as <input type="file" name="file_box">
    $post = array(
        "file_box"=>"@/path/to/myfile.jpg",
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    $response = curl_exec($ch);
?>

On Wed, Aug 10, 2011 at 4:48 PM, Tim Tessier <ttessier_at_swhistlesoft.com>wrote:

> if you performed that on a script that actually captures the command line
> and writes it to a file, then you can make sure that the values you expect
> are actually being passed. You could always use the php curl module however,
> that is not always enabled. So... I would suggest passthrough ( 'bash -c
> echo $username.":".$password'); You may find that the use of single quotes
> is doing something funny.
>
> See:
>
> http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single
>
> I believe that you may be looking for something like:
>
>
> passthru("curl -k -u $username\":\"$password -F \"
> upload=</home/omniupdate/
> public_html/brcctv/25live_imports/Library;type=text/xml\"
> https://webservices.collegenet.com/r25ws/wrd/blueridge/run/events.xml"<https://webservices.collegenet.com/r25ws/wrd/blueridge/run/events.xml%27>
> );
>
>
>
>
>
> On Wed, Aug 10, 2011 at 4:07 PM, Keith Stiles <jk_stiles_at_blueridge.edu>wrote:
>
>> Hi,
>>
>> I have been working on a script that iterates through a CSV file creating
>> some data that is uploaded to a webservices implementation. The script
>> successfully uploads. the command line for the curl in my PHP script is as
>> follows:
>>
>> passthru ('curl -k -u *username*:*password* -F
>> "upload=</home/omniupdate/public_html/brcctv/25live_imports/Library;type=text/xml"
>> https://webservices.collegenet.com/r25ws/wrd/blueridge/run/events.xml');
>>
>> The curl works if I physically enter my username and password in the
>> location. However, if I try to pass the values of variables to the curl as
>> follows:
>>
>> passthru ('curl -k -u $username.":".$password -F
>> "upload=</home/omniupdate/public_html/brcctv/25live_imports/Library;type=text/xml"
>> https://webservices.collegenet.com/r25ws/wrd/blueridge/run/events.xml');
>>
>> The curl command fails to successfully pass the authorization to the
>> webservice.
>>
>> I have verified that the $username and $password variables are populated
>> with the correct values. Any ideas how I could get this to work?
>>
>> Thanks,
>> Keith
>>
>>
>> ***************************************************************
>> Keith Stiles
>> Webmaster/Web Services
>> Blue Ridge Community College
>> 180 West Campus Drive
>> Flat Rock, NC 28731-4728
>> Phone: (828) 694-1894
>>
>> www.blueridge.edu
>>
>> Our mission...enriching the lives of those within our reach through
>> education, training and cultural activities.
>> ***************************************************************
>> E-mail correspondence to and from this address is subject to the
>> North Carolina Public Records Law. (NCGS.Ch.132)
>>
>>
>> -------------------------------------------------------------------
>> List admin: http://cool.haxx.se/list/listinfo/curl-users
>> FAQ: http://curl.haxx.se/docs/faq.html
>> Etiquette: http://curl.haxx.se/mail/etiquette.html
>>
>>
>

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-08-10