2011-09-27 52 views
1

我想通过curllib登录到我的university webmail页面。通过curl登录到邮箱

我的程序下面的代码来做到这一点:


$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); 
$result = curl_exec($ch); 
curl_close($ch); 
echo $result;

,但它会与显示出你的密码是错误的再次重定向到1! 哪里有问题?

+2

问题:你的密码是错误的! – genesis

+0

@genesisφ我使用真正的密码,但我在这里用星号代替它:D和如果我的密码是错误的,它应该打印它。 –

+0

您不能相信错误响应是准确的。你的任何细节都可能是错误的,它可能会有相同的结果。实际上最好不要泄露密码是错误的。确认你的参数,用户名,密码,cookies。 –

回答

2

网站说:

<input type="password" name="pd" size="18"> 

设置:

$post_fields = 'dom=ee.kntu.ac.ir&usr=hoseini&password=*****'; 

更改密码与PD

3

如果您实际检查登录页面的源代码,您会发现密码元素名为pd而不是password

因此,您需要更改此:

$post_fields = 'dom=ee.kntu.ac.ir&usr=hoseini&password=*****'; 

...这样的:

$post_fields = 'dom=ee.kntu.ac.ir&usr=hoseini&pd=*****'; 

这可能不是唯一的问题,但它肯定是一个问题。

+0

该死的太慢了,用captchar: – Talisin