protected function initRequest($url, $options = array())
{
$ch = curl_init();
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // error with open_basedir or safe mode
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
if (isset($options['referer'])) {
curl_setopt($ch, CURLOPT_REFERER, $options['referer']);
}
if (isset($options['headers'])) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $options['headers']);
}
if (isset($options['query'])) {
$url_parts = parse_url($url);
if (isset($url_parts['query'])) {
$query = $url_parts['query'];
if (strlen($query) > 0) {
$query .= '&';
}
$query .= http_build_query($options['query']);
$url = str_replace($url_parts['query'], $query, $url);
} else {
$url_parts['query'] = $options['query'];
$new_query = http_build_query($url_parts['query']);
$url .= '?' . $new_query;
}
}
if (isset($options['data'])) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $options['data']);
}
curl_setopt($ch, CURLOPT_URL, $url);
return $ch;
}