LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 05-30-2005, 11:19 AM   #1
ttxmika
LQ Newbie
 
Registered: May 2005
Location: Montreal, Canada
Distribution: 10.1
Posts: 8

Rep: Reputation: 0
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.
 
Old 05-30-2005, 11:58 AM   #2
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
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).
 
Old 05-30-2005, 12:13 PM   #3
ttxmika
LQ Newbie
 
Registered: May 2005
Location: Montreal, Canada
Distribution: 10.1
Posts: 8

Original Poster
Rep: Reputation: 0
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
 
Old 05-30-2005, 01:12 PM   #4
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
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.
 
Old 05-30-2005, 01:23 PM   #5
ttxmika
LQ Newbie
 
Registered: May 2005
Location: Montreal, Canada
Distribution: 10.1
Posts: 8

Original Poster
Rep: Reputation: 0
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
 
Old 05-30-2005, 02:50 PM   #6
ttxmika
LQ Newbie
 
Registered: May 2005
Location: Montreal, Canada
Distribution: 10.1
Posts: 8

Original Poster
Rep: Reputation: 0
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
 
Old 05-30-2005, 03:55 PM   #7
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 51
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
 
Old 05-30-2005, 04:20 PM   #8
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,437

Rep: Reputation: 93
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
 
Old 05-31-2005, 02:02 AM   #9
cccc828
Member
 
Registered: Feb 2004
Location: Austria
Distribution: Slackware
Posts: 95

Rep: Reputation: 15
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
 
Old 05-31-2005, 07:28 AM   #10
ttxmika
LQ Newbie
 
Registered: May 2005
Location: Montreal, Canada
Distribution: 10.1
Posts: 8

Original Poster
Rep: Reputation: 0
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.
 
Old 05-31-2005, 08:35 AM   #11
cccc828
Member
 
Registered: Feb 2004
Location: Austria
Distribution: Slackware
Posts: 95

Rep: Reputation: 15
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
 
Old 05-31-2005, 11:24 AM   #12
ttxmika
LQ Newbie
 
Registered: May 2005
Location: Montreal, Canada
Distribution: 10.1
Posts: 8

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP/cURL housemusic42 Linux - Networking 0 10-07-2004 02:45 PM
Curl and PHP...? hurieka Linux - Software 6 09-28-2004 11:14 PM
Compile PHP to use Curl pimp1911 Linux - Software 3 09-24-2004 08:56 AM
PHP cURL dependency hell Rotwang Linux - Software 1 08-26-2004 05:43 AM
php and curl Risen Linux - Software 0 09-02-2003 03:41 PM


All times are GMT -5. The time now is 02:42 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration