PHP script to send post data.

The below function will post data to the corresponding site. There are four arguments for this function as you can see. I will explain each parameter in detail.

  • $url — This represents the URL to which we send the POST data to.
  • $header  — This represents the HTTP header used to send POST data.
  • $cookie — This includes the cookies  to be send to authenticate.
  • $p —  This shows the data to be sent as post to the URL.

<?php
function cURL($url, $header, $cookie, $p)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_NOBODY, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, "[proxy server]");
curl_setopt($ch, CURLOPT_PROXYPORT, [proxy port]);
curl_setopt ($ch, CURLOPT_PROXYUSERPWD, "[username]:[password]");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
if ($p) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
}
;
$result = curl_exec($ch);
curl_close($ch);
if ($result) {
return $result;
} else {
return curl_error($ch);
}
}
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s