2011-02-19 5 views
0

У меня есть этот скрипт, который требует allow_url_fopen = On, что не очень хорошая идея, и я хочу изменить curl. Буду признателен, если кто-нибудь сможет мне помочь, как сделать fputs GET.fputs GET to curl

$SH = fsockopen($IP, $Port, $errno, $errstr, 30); 
echo $errstr;  
#$ch = curl_init(); 
#curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
#curl_setopt($ch, CURLOPT_URL, $IP.":".$Port); 
#curl_setopt ($ch, CURLOPT_HEADER, 0); 
    if ($SH){ 
     fputs($SH,"GET /7.html HTTP/1.0\r\nUser-Agent: S_Status (Mozilla Compatible)\r\n\r\n"); 
     $content = ""; 
     while(!feof($SH)) { 
      $content .= fgets($SH, 1000); 
      #content .= curl_setopt($ch, CURLOPT_FILE, $SH); 
     } 
     fclose($SH); 
     #curl_close($ch); 
} 
+0

Можете ли вы заявить конкретный вопрос? – DrDol

ответ

0

Если я правильно понимаю ваш вопрос, вы просто ищете, как отправить запрос HTTP (это то, что ваш fputs($SH, "GET ...") делает, что делается с помощью curl_exec(). Похоже, что это должно работать.

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
curl_setopt($ch, CURLOPT_PORT, $Port); 
curl_setopt($ch, CURLOPT_URL, $IP . '/7.html'); 
curl_setopt($ch, CURLOPT_USERAGENT, 'S_Status (Mozilla Compatible)'); 
//tell curl to return the output, not display it 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
//execute the request 
$content = curl_exec($ch);