NameSilo

Can anyone advise on Curl?

Spaceship Spaceship
Watch

sdtrader

Established Member
Impact
23
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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Pulled this from one of my old scripts, maybe you can hack at it...
PHP:
<?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);

?>
 
1
•••
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:
$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:
$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:
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
 
1
•••
Thanks guys I will let you know how it goes.
 
0
•••

We're social

Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back