2012-10-16 16 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'「但我不知道我該怎麼做?

Plese幫我。謝謝。

+0

我不知道我在哪裏可以在代碼的改變? – user1750573

+0

使用'fsockopen'是**不是一個好的解決方案。改用curl。您可能還想告訴您的託管公司,只要url包含被禁用,url_fopen_wrappers就是完全安全的。 – 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');

相關問題