[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 02-05-2006, 02:26 AM   #1 (permalink)
NamePros Regular
 
sdtrader's Avatar
 
Join Date: Aug 2005
Location: Canada
Posts: 596
5,066.85 NP$ (Donate)

sdtrader is a glorious beacon of lightsdtrader is a glorious beacon of lightsdtrader is a glorious beacon of lightsdtrader is a glorious beacon of lightsdtrader is a glorious beacon of lightsdtrader is a glorious beacon of light


Can anyone advise on Curl?

I've managed to figure out how to convert an fopen command in the past but this one stumps me.If anyone can assist in coming up with a usable curl command it would be greatly appreciated.It comes from cp_email script.
`````````````````````````````````````````````````` `````````
$filepointer = fopen($url,"r");

if($filepointer){

while(!feof($filepointer)){

$buffer = fgets($filepointer, 4096);

$file .= $buffer;

}

fclose($filepointer);

} else {

die
sdtrader is offline  
Old 02-05-2006, 03:16 AM   #2 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services

 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Pulled this from one of my old scripts, maybe you can hack at it...
PHP Code:
<?php

$curl_session
= curl_init();
curl_setopt($curl_session, CURLOPT_URL, "http://www.somedomain.com/index.php?");
curl_setopt($curl_session, CURLOPT_POST, 1);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, "this=".$that);
curl_setopt($curl_session, CURLOPT_HEADER, 0);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($curl_session);

//Do whatever you want with $content here..

curl_close($curl_session);

?>
__________________
Eric is offline  
Old 02-05-2006, 07:03 AM   #3 (permalink)
NamePros Regular
 
moondog's Avatar
 
Join Date: Jun 2004
Posts: 476
3,677.00 NP$ (Donate)

moondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of light


SecondVersion has the basics above. Basically what you have to do is initialize the curl sesison, set the options, then execute the command. The most difficult portion is setting the options.

PHP Code:
$url = 'http://<URL HERE>';
$ch = curl_init($url);
. . .
Set options . . .
$result = curl_exec($ch);
There are loads of options. Depending on what you want to do, you need to either set or not set the RETURN_TRANSFER option.

If you want to DISPLAY the results, then don't set it (or set it to 0). If you want to CAPTURE the data for processing and store it in a variable, you MUST set the "RETURNTRANSFER" variable to 1.

If you want to POST data to a URL (i.e. like you were posting info from a form), then you need to build the query string in a loop- something like:

PHP Code:
$postFields='a=b&c=d&e=f&g=h';
You then set the post fields withe CURLOPT_POSTFIELDS option.

Here is one example I had that interacts with Authorize.net:

PHP Code:

foreach( $authnet_values as $key => $value ) $fields .= "$key=" . urlencode( $value ) . "&";

$ch = curl_init("https://certification.authorize.net/gateway/transact.dll");
curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, "& " )); // use HTTP POST to send form data
$resp = curl_exec($ch); //execute post and get results
curl_close ($ch);
The you can do whatever you need to with the $resp.

Good luck!

-Bob
__________________
The mass purge has begun.
moondog is offline  
Old 02-05-2006, 11:28 AM   #4 (permalink)
NamePros Regular
 
sdtrader's Avatar
 
Join Date: Aug 2005
Location: Canada
Posts: 596
5,066.85 NP$ (Donate)

sdtrader is a glorious beacon of lightsdtrader is a glorious beacon of lightsdtrader is a glorious beacon of lightsdtrader is a glorious beacon of lightsdtrader is a glorious beacon of lightsdtrader is a glorious beacon of light


Thanks guys I will let you know how it goes.
sdtrader is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Php Module help (cUrl) / Alternative squirrelbacon Programming 2 12-01-2005 08:15 AM
Need help with curl install will pay NP dreaminginspiration Programming 5 11-19-2005 01:00 AM
Newbie looking for advise. napalm747 Website Development 8 06-11-2005 07:31 AM
Need Advise! patches Domain Name Discussion 1 04-22-2005 10:35 AM
Registrar Question.. please advise Wanda Domain Name Discussion 4 09-15-2004 04:20 PM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 04:11 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85