Sponsors:
Haxx
|
cURL libcurl PHP ExamplesPHP/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!
Example | Description | Author |
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 linkchecker.php ExampleCheck for a given link in a remote page
Written by Michael Phipps
<?php
/*
Check for Reciporical Link
Use this script to check if reciporical link agreements are being honoured.
In this simple example we are just checking for the existance of a url in
any pair of <a></a> tags on a link page.
*/
// The url that should appear on the link page
$url="http://michaelphipps.com";
// The link page that should contain the url
$link_page="http://curl.haxx.se/libcurl/php/examples/multi.html";
// Use Curl to return the raw source of a webpage to a variable called
$result
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$link_page);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);
// Search for the $url on the $link_page.
/*
Returns the result in an array called $matches
(this regular expression could probably be improved...)
*/
preg_match ("|<[aA] (.+?)".$url."(.+?)>(.+?)<\/[aA]>|i", $result, $matches);
// See if there were any matches
/*
(note preg_match only returns the first match,
use preg_match_all to return all matches)
*/
if (count($matches)>0){
// if there are items in the array, then there was a match.
echo "The link exists on the target website";
print_r($matches);
/*
If you require very specific link text you can use the information
returned in the $matches array to further assess if your website is
being linked the way you want.
*/
}else{
// if there are no items in the array, then no matches were found.
echo "The link does not exist on the target website";
}
?>
|