Slackware This Forum is for the discussion of Slackware Linux.
|
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-30-2005, 11:19 AM
|
#1
|
LQ Newbie
Registered: May 2005
Location: Montreal, Canada
Distribution: 10.1
Posts: 8
Rep:
|
Curl under PHP - more help please
Hi folks,
Being a unix veteran (SCO, 20 years or so) I am somewhat green to Linux, I have installed slackware 10.1 on a box, all options except for international languages where installed.
(Installation was error-free and was a charm, I have *never* installed a *nix this fast before)
My problem is that I can't get PHP to work with Curl, the Apache log tells me:
PHP fatal error: Call to undefined function: curl_init() in /var/www/htdocs/...
From what I gather, I need to recompile PHP with curl support (--with-curl[=DIR]) and for the life of me I have no clue where to begin.
Do I need to acquire the PHP source and recompile? or is the source already installed via slackware installation?
A somewhat walkthrough from a Linux guru would be greatly appreciated.
Thanks
Marc
Last edited by ttxmika; 05-30-2005 at 03:13 PM.
|
|
|
05-30-2005, 11:58 AM
|
#2
|
Member
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468
Rep:
|
Hi Marc, welcome to Linux. What's the PHP code you're using?
You should be able to call curl externally with system() or exec() if you have curl installed (which it is with Slackware).
|
|
|
05-30-2005, 12:13 PM
|
#3
|
LQ Newbie
Registered: May 2005
Location: Montreal, Canada
Distribution: 10.1
Posts: 8
Original Poster
Rep:
|
Quote:
Originally posted by michaelsanford
Hi Marc, welcome to Linux. What's the PHP code you're using?
You should be able to call curl externally with system() or exec() if you have curl installed (which it is with Slackware).
|
Ultimately my goal would be to run this from the unix prompt via curl, but the credit-card processing outfit only supplies PHP code that
I'm trying to convert so as to use curl directly without the use of PHP.
the snipit from the PHP code that causes the error is
$data_stream is put together from a PHP web form POST (parm=val&parm=val etc..)
$url is the payment processing outfit's script
//send the data and retrieve response from FirePay
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_stream);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$result_tmp = curl_exec ($ch);
curl_close ($ch);
If I could have the equivalent for the above code but for command line curl, I would be happy as a p*g in sh*t.
Thanks for asking.
Marc
|
|
|
05-30-2005, 01:12 PM
|
#4
|
Member
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468
Rep:
|
Et un montrealais en plus! Didn't notice.
So, I have a feeling that PHP that comes with Slackware 10.1 default is 4.0.1 which doesn't support curl_* per se. I would assume the command line would look something like this, if you wanted to pass it to exec()
PHP Code:
$curl_query = "/usr/bin/curl --options";
$curl_query_escaped = escapeshellcmd($curl_query);
$last_line = system($curl_query_escaped, $return_value);
I'm not entirely clear on which options you'd need to set, but look at the php.net documentation for curl_init() and compare it to man curl and try to flesh it out. It shouldn't be too hard.
|
|
|
05-30-2005, 01:23 PM
|
#5
|
LQ Newbie
Registered: May 2005
Location: Montreal, Canada
Distribution: 10.1
Posts: 8
Original Poster
Rep:
|
Quote:
Originally posted by michaelsanford
Et un montrealais en plus! Didn't notice.
So, I have a feeling that PHP that comes with Slackware 10.1 default is 4.0.1 which doesn't support curl_* per se. I would assume the command line would look something like this, if you wanted to pass it to exec()
PHP Code:
$curl_query = "/usr/bin/curl --options";
$curl_query_escaped = escapeshellcmd($curl_query);
$last_line = system($curl_query_escaped, $return_value);
I'm not entirely clear on which options you'd need to set, but look at the php.net documentation for curl_init() and compare it to man curl and try to flesh it out. It shouldn't be too hard.
|
Yep, greater Montreal area.
I'll lookup and compare the options as you mentioned, so long as I can
get it to run from the unix prompt, I can then build a bubble around it in (bourne, bash, perl, whatever) for my purposes.
Cheers,
Marc
|
|
|
05-30-2005, 02:50 PM
|
#6
|
LQ Newbie
Registered: May 2005
Location: Montreal, Canada
Distribution: 10.1
Posts: 8
Original Poster
Rep:
|
Well after some "fleshing" out I have bumped into a cement wall
The php script sets options as follows
(the equivalant curl command line switch is in braces)
CUROPT_POST, 1
( --data )
CUROPT_POSTFIELDS, $data_stream
( URL Encoded Data )
CUROPT_URL, $url
( --url url )
CUROPT_SSL_VERIFYHOST, 2
!!!!! ( unable to find equivalent in Curl manual )
CUROPT_RETURNTRANSFER, 1
( not needed for command line use )
CUROPT_SSL_VERIFYPEER, FALSE
!!!!! ( unable to find equivalent in Curl manual )
Then the command line would be:
curl --data URLencodedData --url url --VERIFYHOST ? --VERIFYPEER ?
Any help would be appreciated.
Many Thanks,
Marc
|
|
|
05-30-2005, 03:55 PM
|
#7
|
Senior Member
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145
Rep:
|
CUROPT_SSL_VERIFYPEER, FALSE
I think that would be equal to --cacert empty
CUROPT_SSL_VERIFYHOST, 2
I think this is enable by default and disabled by using --insecure
|
|
|
05-30-2005, 04:20 PM
|
#8
|
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 6,797
|
To send data to a post form, try using -d (or --data) one for
each variable to post, eg :
Code:
curl -d var1=val -d var2=val -d var3=val -o out.html $url
|
|
|
05-31-2005, 02:02 AM
|
#9
|
Member
Registered: Feb 2004
Location: Austria
Distribution: Slackware
Posts: 95
Rep:
|
Ah, do you really think it is clever to mix up different techniques, when you can really do all this with php-only?
Installing PHP from source is not that hard ( Documentation).
Also you could do the post-request without CURL as well: Example
|
|
|
05-31-2005, 07:28 AM
|
#10
|
LQ Newbie
Registered: May 2005
Location: Montreal, Canada
Distribution: 10.1
Posts: 8
Original Poster
Rep:
|
Quote:
Originally posted by cccc828
Ah, do you really think it is clever to mix up different techniques, when you can really do all this with php-only?
Installing PHP from source is not that hard (Documentation).
Also you could do the post-request without CURL as well: Example
|
I'm trying to *not* use PHP and go to command line only, problem being PHP, cURL is very green to me and am having trouble creating the equivalent of post#3 but for command line use only.
Basically I will have data pre-formatted as var=val&var=val etc... from a database and need to send this info to the command line cURL and having trouble converting the PHP cURL options (post #3) to command line ones.
I have data (var=val&var=val), the remote URL, no certificate and this must be sent SSL.
Cheers,
Marc
Last edited by ttxmika; 05-31-2005 at 07:34 AM.
|
|
|
05-31-2005, 08:35 AM
|
#11
|
Member
Registered: Feb 2004
Location: Austria
Distribution: Slackware
Posts: 95
Rep:
|
Oh so I totally misunderstood you, sorry =)
If I understood the Man-page correctly, it could work that way:
Code:
var = "foo=text&bar=othertext&banana=apple" //ensure that the content is "urlencoded"!
curl -d var -ciphers SSLv3+SSLv2 -o out.txt http://www.example.com/post.php //check [URL=http://www.openssl.org/docs/apps/ciphers.html] for the ciphers
This could work. However, try to use a sniffer such as snort to check the HTTP-Traffic. It is not that easy to debug HTTP-Applications without knowing what Headers are sent and received. Also you might want to try to do what you want to do without SSL first, get the basics to work and then try to master the SSL part. This is also a good idea, because it is kinda hard to debug encrypted POST information.
cccc828
|
|
|
05-31-2005, 11:24 AM
|
#12
|
LQ Newbie
Registered: May 2005
Location: Montreal, Canada
Distribution: 10.1
Posts: 8
Original Poster
Rep:
|
Well I decided to just go ahead a manually try one on the newly installed Slackware box, turns out the following works just fine
curl -d erlencodeddata https:/host/url
curl -d erlencodeddata https:/host/url -v
I have also acquired and compiled cURL and openSSL onto our main servers (SCO Unix) and they work just great there too.
hats-off to the open-source community !
All your replies have help in my hunt to make this work
Thanks a millions to all
Cheers,
Marc
|
|
|
All times are GMT -5. The time now is 06:47 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|