2010-08-15 2 views
-5

이 Perl 코드를 PHP 코드로 변환 할 수 있습니까?Perl에서 PHP로 번역

use HTTP::Request::Common qw(POST); 
use LWP::UserAgent; 
$ua = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5'); 
$ua -> timeout(0.5); 
my $req = POST 'http://forums.shooshtime.com/', 
[ vb_login_username => 'mehdi' , vb_login_password => '***' , go => 'submit']; 
my $content = $ua->request($req); 

미리 감사드립니다.

+2

[cURL 라이브러리] (http://php.net/manual/en/book.curl.php)를보십시오. – Aillyn

+0

닫힌 후에 표시됩니다. cURL은 차선책입니다. 그것을 사용하지 않은 다른 응답을 보는 것을 좋아했을 것입니다. –

답변

2

여기 있습니다. 완전한 코드가 PHP로 변환 됨 :

<?php 
//set URL 
$url = 'http://forums.shooshtime.com/'; 

//set POST variables 
$fields = array(
    'vb_login_username' => 'mehdi', 
    'vb_login_password' => '***' , 
    'go' => 'submit' 
       ); 

// set user agent 
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5'; 

//open connection 
$ch = curl_init(); 

//set the url, POST data, UserAgent, Timeout, etc. 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields); 
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 500); //time out of 0.5 seconds. 

//execute post 
$content = curl_exec($ch); 

//close connection 
curl_close($ch); 
?>