2012-10-16 4 views
0

내 사이트에 curreny 코드를 사용하고 있습니다. 줄내 사이트에서 fsockopen을 어떻게 사용할 수 있습니까?

<?php 
$contents = file_get_contents('http://www.tcmb.gov.tr/kurlar/today.html'); 
$contents = iconv("windows-1254" , "utf8" , $contents); 

$dollar = preg_match('~ABD DOLARI\s+(.+?)\s+(.+?)\s+~i', $contents, $matches) ? array('buying' => $matches[1], 'selling' => $matches[2]) : ''; 
$euro = preg_match('~EURO\s+(.+?)\s+(.+?)\s+~i', $contents, $matches) ? array('buying' => $matches[1], 'selling' => $matches[2]) : ''; 
$gbp = preg_match('~İNGİLİZ STERLİNİ\s+(.+?)\s+(.+?)\s+~i', $contents, $matches) ? array('buying' => $matches[1], 'selling' => $matches[2]) : ''; 
$chf = preg_match('~İSVİÇRE FRANGI\s+(.+?)\s+(.+?)\s+~i', $contents, $matches) ? array('buying' => $matches[1], 'selling' => $matches[2]) : ''; 

echo ' 
    <table class="form" style="background:#fff;width:300px;margin-left:14px;"> 
     <tr style="border-bottom:1px solid #e4e4e4;"> 
     .. 

을하지만 오늘 내 사이트가 오류 : 다음으로

Warning: eval() (/var/www/vhosts/mysite.com/httpdocs/modules/php/php.module(80) : eval()'d code dosyasının 2 satırı) içinde file_get_contents() [function.file-get-contents]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0. 

나는이 문제에 대해 지원을 호스팅에 내 부탁 않았고, 그들이 말하는됩니다

"사용하지 마십시오 fopen 옵션을 사용하십시오. 'fsockopen'을 사용하십시오. "하지만 어떻게 할 수 있을지 모르겠습니다.

나를 도와주세요. 감사.

+0

내가 코드에서 변경할 수있는 모르겠어요 거기 변경에서? – user1750573

+0

'fsockopen '을 사용하는 것은 좋은 해결책이 아닙니다 **. 대신 컬을 사용하십시오. url_fopen_wrappers는 url_fopen_wrappers가 URL 포함이 비활성화되어있는 한 완벽하게 안전하다는 것을 호스팅 회사에 알리고 싶을 수도 있습니다. – ThiefMaster

+0

편집증에 의한 보안이 다시 공격합니다! –

답변

1

대신 curl을 사용하십시오. 원격 서버에서 file_get_contents를 대체하는 기능은 다음과 같습니다

function get_web_page($url) { 
    $options = array(
    CURLOPT_RETURNTRANSFER => true,  // return web page 
    CURLOPT_HEADER   => false, // don't return headers 
    CURLOPT_FOLLOWLOCATION => true,  // follow redirects 
    CURLOPT_ENCODING  => "",  // handle all encodings 
    CURLOPT_USERAGENT  => "spider", // who am i 
    CURLOPT_AUTOREFERER => true,  // set referer on redirect 
    CURLOPT_CONNECTTIMEOUT => 120,  // timeout on connect 
    CURLOPT_TIMEOUT  => 120,  // timeout on response 
    CURLOPT_MAXREDIRS  => 10,  // stop after 10 redirects 
    ); 

    $ch  = curl_init($url); 
    curl_setopt_array($ch, $options); 
    $content = curl_exec($ch); 
    $err  = curl_errno($ch); 
    $errmsg = curl_error($ch); 
    $header = curl_getinfo($ch); 
    curl_close($ch); 

    $header['errno'] = $err; 
    $header['errmsg'] = $errmsg; 
    $header['content'] = $content; 
     //If you want error information, 'return $header;' instead. 
    return $content; 
} 

$contents = file_get_contents('http://www.tcmb.gov.tr/kurlar/today.html');$contents = get_web_page('http://www.tcmb.gov.tr/kurlar/today.html');

관련 문제