Monthly Archives: September 2010

php curl post example

#!/usr/bin/php
<?php

$login = “login:pass”;
$url = “http://url”;
$post_fields = array(‘param1’ => ‘value1’);

$useragent = “Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 GTB7.1”;

$ch = curl_init();
$fp = fopen(“out.txt”, “w”);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_USERPWD, $login);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>