Dec 17

Wrote this for one of my projects - hopefully it helps you out a little bit. POST data needs to be formatted variable1=value&variable2=value2 and urlencoded.

function CURL($url, $postdat=""){
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
	if($postdat){
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $postdat);
	}
	while(!$dat) $dat = curl_exec($ch);
	curl_close($ch);
	return $dat;
}

Examples:

$dat = CURL("http://google.com");
$dat = CURL("http://site.com/post.php", "search=bunnies");

Sorry I haven't had much content lately: finals this week :-\

  • Digg
  • StumbleUpon
  • del.icio.us
  • Reddit

5 Responses

  1. G-Brain Says:

    Complexity.

  2. Katalyst Says:

    CURL using Firefox? You must drive a Volvo too.

  3. admin Says:

    You're both right, of course, but it doesn't make me hate you any less.

  4. TechCow Says:

    Just found Curl in my server stats and searched for curl on google and ended up here.

    it looks like someone is scraping my content?

  5. admin Says:

    More than likely, yes. You can probably block that user-agent without it affecting your normal traffic if you don't want them to.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.