Here ya go. Commented for easy use.
PHP Code:
<?
/*
___ _
/ _ \___ _ __ ___ _ __ ___ | | ___
/ /_\/ _ \| '_ ` _ \| '_ ` _ \| |/ _ \
/ /_\\ (_) | | | | | | | | | | | | __/
\____/\___/|_| |_| |_|_| |_| |_|_|\___|
Original filename: > curl.function.php
E-Mail: > gommle@gmail.com
MSN: > datafrik2003@hotmail.com
*/
//--------------------------------------------\\
##### ~ cURL function ~ #####
#----------------------------------------------#
// Function to send requests using Curl
// Builtin cookie handling for *nix systems.
// For Wintendo you need to edit the path in
// CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE
## Usage ##
# Return all recieved data to $html.
// $html = curl( 'http://freakforum.nu/login.php',
// 'user=lolol&pass=lolol',
// 'http://freakforum.nu/',
// '12.34.56.78:8080' );
# Only the first param is needed to fetch a page. 'http://digg.com/'
# GET data should be included in the first param. 'http://lol.com/?page=rofl'
# The second is POST data, in the same format as GET. 'user=me&pass=you'
# Referer: The page you "came from". 'http://neopets.com/lab2.phtml'
# Proxy: If your server gets banned from some online game '123.123.123.123:1337'
function curl($url, $data='', $referer='', $proxy='')
{
// Make config available
global $config;
// Initiate Curl
$ch = curl_init();
// Set URL to fetch
curl_setopt($ch, CURLOPT_URL, $url);
// Set User Agent to remote browser
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER[HTTP_USER_AGENT]);
// Follow location headers
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// Set referer
if($referer) { curl_setopt($ch, CURLOPT_REFERER, $referer); }
// Don't return data immediately
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Get cookies from this file
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/'.$_SERVER[HTTP_REMOTE_ADDR].'cookie.txt');
// Load cookies from this file
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/'.$_SERVER[HTTP_REMOTE_ADDR].'cookie.txt');
// Use a proxy if set
if($proxy) {
// Enable proxies
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
// Set timeout for proxy, so php doesn't timeout.
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
// Use this proxy
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
// Set POST options if data is specified
if($data) {
// Use method POST
curl_setopt($ch, CURLOPT_POST, 1);
// POST this data
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$data = curl_exec($ch);
return($data);
}
###################################################
?>