Ejemplo n.º 1
0
/**
 * Retrieve url
 *
 * @return mixed string if successfull, FALSE if failed
 * @author AvB
 **/
function get_url($url, $options = array())
{
    $http = array('header' => '');
    $http['user_agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A';
    if (isset($options['method'])) {
        $http['method'] = $options['method'];
        if ($options['method'] = 'POST') {
            $http['header'] .= "Content-type: application/x-www-form-urlencoded\r\n";
        }
    }
    if (isset($options['data'])) {
        $http['content'] = http_build_query($options['data']);
        $http['header'] .= "Content-Length: " . strlen($http['content']) . "\r\n";
    }
    // Add optional timeout
    if (conf('request_timeout')) {
        $http['timeout'] = conf('request_timeout');
    }
    $context_options = array('http' => $http);
    // Add optional proxy settings
    if (conf('proxy')) {
        add_proxy_server($context_options);
    }
    $context = stream_context_create($context_options);
    return @file_get_contents($url, FALSE, $context);
}
Ejemplo n.º 2
0
/**
 * Retrieve url
 *
 * @return mixed string if successfull, FALSE if failed
 * @author AvB
 **/
function get_url($url, $options = array())
{
    $http = array('header' => '');
    if (isset($options['method'])) {
        $http['method'] = $options['method'];
        if ($options['method'] = 'POST') {
            $http['header'] .= "Content-type: application/x-www-form-urlencoded\r\n";
        }
    }
    if (isset($options['data'])) {
        $http['content'] = http_build_query($options['data']);
        $http['header'] .= "Content-Length: " . strlen($http['content']) . "\r\n";
    }
    // Add optional timeout
    if (conf('request_timeout')) {
        $http['timeout'] = conf('request_timeout');
    }
    $context_options = array('http' => $http);
    // Add optional proxy settings
    if (conf('proxy')) {
        add_proxy_server($context_options);
    }
    $context = stream_context_create($context_options);
    return file_get_contents($url, FALSE, $context);
}