cURL
Your ad here would be seen by 100,000 unique vistors every month File upload component for ASP.NET
libcurl
Automatically get a mirror near you

More Internet Tools Here, Visit New Easy Freeware, Free Programs PC, Shareware Super Downloads, Printers, Coupon code, Hotel booking online, Hotel Berlin, Hotelbooking, Munich Fair Hotel, München Hotel, Iphone unlock, acai, Gian Page, Collection of Natalie, Diamond rings and Engagement Rings, Hotel Berlin, madonna lyrics, beyonce lyrics

Shopping cart software, Online file storage and sharing, Online photo storage and sharing, Online store builder, Online contact management, Online email marketing, Online project management, Online issue tracking, Online notepad, Online publishing

SourceForge.net Logo

cURL > libcurl > PHP > Examples

PHP/CURL Examples Collection

We try to collect examples on how to program the PHP/CURL interface here. If you have any source snippests you want to share with the rest of the world, please let us know!

ExampleDescriptionAuthor
blogpost Post a blog entry to blogger.com using their "Atom" XML-based API. Michael Phipps
callbacks Set callback functions to receive the HTTP response as it comes through. Keyvan Minoukadeh
cookiejar Login to on one page and then get another page passing all cookies from the first page along Mitchell
customrequest CURLOPT_CUSTOMREQUEST usage shown
ebay_login Mimics a browser and logs in to ebay Imran Khalid
ftpupload FTP upload to a remote site Daniel Stenberg
getbinarypageinvar Get the contents of a web page as a binary into a php variable.
getpageinvar Get the contents of a remote web page into a PHP variable
google-analytics-login This code posts all the correct post fields to Googles universal Account Services login and brings the user directly to the AdSense Overview page. Cookies are used in this example as well as setting the USER AGENT and REFERRER HTTP headers. AskApache.com
httpfileupload Shows how to submit and upload a file to a HTML upload form. Daniel Stenberg
linkchecker Check for a given link in a remote page Michael Phipps
multi Shows how to fetch several documents at once by using the multi interface Roman Rozanov
multipartpost Using a multipart/form-post file upload form on a web page. Pete James
put Perform a HTTP PUT to a remote site Julian Bond
resizejpg Download a remote image, resize it and show it to the user Michael Phipps
rss-adsense Follow your Adsense earnings with an RSS reader Ozh
simpleget Get a URL
simplepost Basic HTTP POST operation

The callbacks.php Example

Set callback functions to receive the HTTP response as it comes through. Written by Keyvan Minoukadeh

<?php
/*
Author: Keyvan Minoukadeh

This script demonstrates how you can set callback functions to receive the
HTTP response as it comes through.

The advantage of this is that you don't have to wait for the whole response
to be returned before you start work on it, you can monitor for certain
headers, start outputting while you're receiving, etc..

I wasn't aware these cURL options were available in PHP, but noticed them being
used by Alan Knowles: <http://docs.akbkhome.com/phpmole/phpmole_webfetch.html>

For more info on CURLOPT_HEADERFUNCTION and CURLOPT_WRITEFUNCTION see:
<http://curl.haxx.se/libcurl/c/curl_easy_setopt.html>
*/

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://www.php.net/');
// Set callback function for headers
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');
// Set callback function for body
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body');

curl_exec($ch);

if ($error = curl_error($ch)) {
    echo "Error: $error<br />\n";
}

// define callback functions

// Notes from <http://curl.haxx.se/libcurl/c/curl_easy_setopt.html>:
// Return the number of bytes actually written or return -1 to signal error to
// the library (it will  cause it to abort the transfer with a CURLE_WRITE_ERROR
// return code). (Added in 7.7.2)
function read_header($ch, $string)
{
    $length = strlen($string);
    echo "Header: $string<br />\n";
    return $length;
}

// Notes from <http://curl.haxx.se/libcurl/c/curl_easy_setopt.html>:
// Return the number of bytes actually taken care of.  If that amount differs
// from the amount passed to your function, it'll signal an error to the library
// and it will abort the transfer and return CURLE_WRITE_ERROR.
function read_body($ch, $string)
{
    $length = strlen($string);
    echo "Received $length bytes<br />\n";
    return $length;
}

?> 

donate! web site info