views:

96

answers:

1

may you convert this Perl code to PHP code ?

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);

Thanks in Advance .

+1  A: 

Here you go. Complete code converted to 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);
?>
shamittomar