0
$cookie="cookie.txt"; 
$data = array();
$data['global_id'] = "raj";
$data['global_password'] = "raj";

foreach ($data as $key => $value){
    $post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);


$curl_connection = curl_init('http://somedomain.com/cgi-bin/login.pl');
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_REFERER, 'http://somedomain.com/cgi-bin/login.pl');
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($curl_connection, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($curl_connection, CURL_COOKIEFILE, '');
$result = curl_exec($curl_connection);

if($result == "success"){
    header("Location: http://somedomain.com/cgi-bin/index.pl");
}
else{
    echo "Login failed";
}

//close the connection
curl_close($curl_connection);

有什么问题...我无法登录

执行此脚本后,如果我转到http://somedomain.com/cgi-bin/index.pl 它应该登录。我怎样才能做到这一点 ?

4

3 回答 3

1

你应该设置CURLOPT_RETURNTRANSFERtrue. 可能你的 $result 是空的。

此外,在设置时,CURLOPT_REFERER您显然使用了错误的变量。($ch)

编辑:

似乎缺少以下行:

curl_setopt($curl_connection, CURLOPT_POST, true);
于 2012-08-09T11:44:28.543 回答
0

试试这个:

curl_setopt($ch, CURLOPT_SSLVERSION, 3); // OpenSSL issue
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);  // Wildcard certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

否则,您应该了解SSL服务器的配置。这可能是一个问题。

您也可以将POSTvars 设置为数组:

curl_setopt($ch, CURLOPT_POSTFIELDS, array('param1' => 'value1', 'param2' => 'value2'));

更新:你正在尝试使用SSLover HTTP

$curl_connection = curl_init('http://somedomain.com/cgi-bin/login.pl');

尝试更正您的URLto HTTPS

于 2012-08-09T12:06:48.577 回答
0

尝试修复您的 curl opt 代码,如下所示:

curl_setopt($curl_connection, CURLOPT_POST, true);
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURL_COOKIEFILE, $cookie);
curl_setopt($curl_connection, CURL_VERBOSE, true);

希望这有帮助..

于 2012-12-05T20:08:45.727 回答