$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 它应该登录。我怎样才能做到这一点 ?