I wanna login to my university webmail page by curllib.
I program following code to do that:
$url = 'http://eetd.kntu.ac.ir/mda2.asp';
$reffer = 'http://sabamail.kntu.ac.ir:3000/WorldClient.dll?View=Main';
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
$cookie_file_path = "/var/www/cookie.txt";
$post_fields = 'dom=ee.kntu.ac.ir&usr=hoseini&password=*****';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch,CURLOPT_REFERER,$reffer);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$re开发者_如何学运维sult = curl_exec($ch);
curl_close($ch);
echo $result;
but it will redirect to 1 again with out showing your password is wrong! where is problem?
If you actually examine the source code of the login page, you will find the password element is named pd
and not password
.
Therefore you need to change this:
$post_fields = 'dom=ee.kntu.ac.ir&usr=hoseini&password=*****';
...to this:
$post_fields = 'dom=ee.kntu.ac.ir&usr=hoseini&pd=*****';
This may not be the only issue, but it is certainly an issue.
site says:
<input type="password" name="pd" size="18">
you set:
$post_fields = 'dom=ee.kntu.ac.ir&usr=hoseini&password=*****';
change password to pd
精彩评论