Простая и полезная функция PHP http или HTTPS запроса c курл (CURL), для работы CURL должна быть установлена расширения PHP CURL
function http_request($url, $post, $ssl = false, $headers = '', $uagent = '') {
if (empty($url)) { return false; }
$_post = Array();
if (is_array($post)){
foreach ($post as $name => $value){
$_post[] = $name.'='.urlencode($value);
}
}
$ch = curl_init($url);
if ($ssl) {
//если соединяемся с https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if (is_array($post)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, join('&', $_post));
}
if (is_array($headers)) {
//если заданы какие-то заголовки для браузера
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
if (!empty($uagent)){
//если задан UserAgent
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
}
$result = curl_exec($ch);
if (curl_errno($ch) != 0 && empty($result)) { $result = false; }
curl_close($ch);
return $result;
}