网站推广.NET

网站推广.NET

php模拟登陆教务出现object moved to here,加上了curl_setopt($ch, CURLOPTFOLLOWLOCATION, 1);

来源:互联网

学生一个,自己在摸索,希望大神们百忙之中指导一下,不知道到底哪里出现了问题
模拟登陆教务网站出现问题,求教大神们

教务网站http://xk.shnu.edu.cn:82/index.aspx
测试账号120154728           123612
登陆界面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type"/>  <title>a</title></head><body><p class="header">绑定学号    </p>    <p class="content">        <p class="notice"><br/>初始密码身份证后6位</p>            <p class="form">            <form action="http://localhost/ff/post.php" method="post">                    <p class="row">                   <span class="label">学  号</span><br/>                   <input class="input" type="text" name="stuno" value="" /><br/>                    </p>                    <p class="row">                        <span class="label">密  码</span><br/>                        <input class="input" type="password" name="stupwd" value="" /><br/>                    </p><p class="row">                        <span class="label">验证码</span><br/>                        <input class="input" type="text" name="stuyzm" value="" /><br/>                    </p><p class="row"><input class="<strong></strong>" type="submit" value="提交" /></p><iframe id='img' src="i.php" scrolling="No" frameborder="0"></iframe>             </form></body></html>

获取验证码
<?php$url = "http://xk.shnu.edu.cn:82/ValidateCode.aspx?codeLen=5&aFineness=90&ImgWidth=85&PosX=4&PosY=1&FontFamily=Arial&FontSize=14&FontStyle=3";        $filedir = SITE_PATH."/TMP/Cookies";        $cookie_file =  $filedir."/cookie.txt";        $ch = curl_init();        curl_setopt($ch, CURLOPT_URL, $url);        curl_setopt($ch, CURLOPT_HEADER, 0);        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); //        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);        curl_setopt($ch, CURLOPT_TIMEOUT, "10");        header("Content-type:image/gif");         echo  curl_exec($ch);        curl_close($ch); ?>

post页面
<?php$user=$_POST["stuno"];$password=$_POST["stupwd"];$yzm=$_POST["stuyzm"];//echo $user;//echo $password;//echo $yzm;$cookie_file = tempnam('./temp','cookie');$login_url = 'http://xk.shnu.edu.cn:82/index.aspx';$post_fields = array("cktime"=>"3153600","txtUserID"=>$user,"txtUserPwd"=>$password,"txtValidateCode"=>$yzm);    $ch = curl_init($login_url);    curl_setopt($ch, CURLOPT_HEADER, 0);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPTFOLLOWLOCATION, 1);    curl_setopt($ch, CURLOPT_POST, 1);    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);    curl_exec($ch);    curl_close($ch);        $url='http://xk.shnu.edu.cn:82/index.aspx';    $ch = curl_init($url);    curl_setopt($ch, CURLOPT_HEADER, 0);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);curl_setopt($ch, CURLOPTFOLLOWLOCATION, 1);    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);    $contents = curl_exec($ch);    curl_close($ch);?>


回复讨论(解决方案)

大神们 来帮帮忙

CURLOPTFOLLOWLOCATION
应为
CURLOPT_FOLLOWLOCATION

还有就是你的这些代码的执行次序

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

而且你的验证码也不需要curl获取。直接
即可

CURLOPTFOLLOWLOCATION
应为
CURLOPT_FOLLOWLOCATION

还有就是你的这些代码的执行次序
代码执行次序应该是怎样的啊?代码还有其他的问题吗?
现在改好了 没有重定向的信息了 但是页面显示还是不对

而且你的验证码也不需要curl获取。直接
即可
那如何知道验证码是否与网站上的一致?目前进去变成这样子了

curl 访问 http://xk.shnu.edu.cn:82/index.aspx 用于获取 cookie
解析出验证码图片地址
表单页,填写用户信息和验证码值
curl 提交

curl 访问 http://xk.shnu.edu.cn:82/index.aspx 用于获取 cookie
解析出验证码图片地址
表单页,填写用户信息和验证码值
curl 提交
我的流程是这样子的啊 模拟之后的页面 跟直接在地址栏里输入网址 产生的页面一样 根本不是个人的信息

流程中只第一次才有 curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
以后每部都不能有,不然读到的 cookie 会改变

流程中只第一次才有 curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
以后每部都不能有,不然读到的 cookie 会改变
刚接触 还是不理解
意思是 我的post页面里不再需要curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);吗?

而且你的验证码也不需要curl获取。直接
即可
怎么知道验证码需不需要curl获取啊?

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
我的用户名密码验证码数据是不是还是没有传过去啊?

我 #7 没有说清楚吗?

我 #7 没有说清楚吗?
我的流程应该是你说的那个样子啊

他的登录表单里还有两个隐藏域,你也传过去里吗

他的登录表单里还有两个隐藏域,你也传过去里吗
版主 我加上隐藏值了 也还是不行

<?php$user=$_POST["stuno"];$password=$_POST["stupwd"];$yzm=$_POST["stuyzm"];//echo $user;//echo $password;//echo $yzm;$cookie_file = tempnam('./temp','cookie');$login_url = 'http://xk.shnu.edu.cn:82/index.aspx';$post_fields = array("cktime"=>"3153600","__VIEWSTATE"=>"/wEPDwUKMTU3NjIwMDY1MQ9kFgICAw9kFgQCEQ88KwAJAQAPFgQeCERhdGFLZXlzFgAeC18hSXRlbUNvdW50AghkFhBmD2QWAmYPFQQx5pys5a2m5pyf5a2m55Sf5oiQ57up6K+35LqOMjAxNOW5tDHmnIgyNuaXpeafpeivoggwMDAwMDAzMzHmnKzlrabmnJ/lrabnlJ/miJDnu6nor7fkuo4yMDE05bm0MeaciDI25pel5p+l6K+iCDIwMTQwMTE2ZAIBD2QWAmYPFQQ3MjAxMee6p+acrOenkeeUn+WPr+S7peWPguWKoOS4iua1t+W4gumrmOagoeWFseS6q+ivvueoiwgwMDAwMDAzMjcyMDEx57qn5pys56eR55Sf5Y+v5Lul5Y+C5Yqg5LiK5rW35biC6auY5qCh5YWx5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IfljZcIMjAxMzA5MDZkAhMPD2QPDxQrAAEWCB4ETmFtZQULc3RyQ29uZHRpb24eBFR5cGULKVxTeXN0ZW0uVHlwZUNvZGUsIG1zY29ybGliLCBWZXJzaW9uPTIuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjc3YTVjNTYxOTM0ZTA4ORIeDERlZmF1bHRWYWx1ZQVlIGlkX01zZyBpbiAoIHNlbGVjdCBpZF9Nc2cgZnJvbSBYeE1zZ05vdGlmeVJvbGUgd2hlcmUgUm9sZUlkID0gJzAwMDEwMDA1Jykgb3JkZXIgYnkgcmVsZWFzZWRhdGUgZGVzYyAeDlBhcmFtZXRlclZhbHVlZBQrAQECA2RkZGIgE9UDulG9GvRO4dsU+SdCCEFM","__EVENTVALIDATION"=>"/wEWBgKY0u7vCwLT8dy8BQLG8eCkDwKuqciQCQKC3IeGDAKO8J4Nk+MLn7wUWUDvvoz1eyVjqKX9ZAs=","pwuser"=>$user,"pwpwd"=>$password);    $ch = curl_init($login_url);    curl_setopt($ch, CURLOPT_HEADER, 0);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($ch, CURLOPT_POST, 1);    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);curl_exec($ch);    curl_close($ch);        $url='http://xk.shnu.edu.cn:82/StudentManage/wfmXsStuBaseUpdate.aspx';    $ch = curl_init($url);    curl_setopt($ch, CURLOPT_HEADER, 0);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);    $contents = curl_exec($ch);    curl_close($ch);?>

你在 pos 页面中
$cookie_file = tempnam('./temp','cookie');
你在获取验证码程序中
$cookie_file = $filedir."/cookie.txt";

整个过程中使用了不同的 cookie 文件,显然不能保证 cookie 是一致的

你在 pos 页面中
$cookie_file = tempnam('./temp','cookie');
你在获取验证码程序中
$cookie_file = $filedir."/cookie.txt";

整个过程中使用了不同的 cookie 文件,显然不能保证 cookie 是一致的 我用firebug调试 发现隐藏值没有传进去,为什么啊?
其他的值都有,传输方式跟其他的一样

$user=$_POST["stuno"];$password=$_POST["stupwd"];$yzm=$_POST["stuyzm"];//echo $user;//echo $password;//echo $yzm;$cookie_file = tempnam('./temp','cookie');$login_url = 'http://xk.shnu.edu.cn:82/index.aspx';$post_fields = array("cktime"=>"3153600","__VIEWSTATE"=>"/wEPDwUKMTU3NjIwMDY1MQ9kFgICAw9kFgQCEQ88KwAJAQAPFgQeCERhdGFLZXlzFgAeC18hSXRlbUNvdW50AghkFhBmD2QWAmYPFQQx5pys5a2m5pyf5a2m55Sf5oiQ57up6K+35LqOMjAxNOW5tDHmnIgyNuaXpeafpeivoggwMDAwMDAzMzHmnKzlrabmnJ/lrabnlJ/miJDnu6nor7fkuo4yMDE05bm0MeaciDI25pel5p+l6K+iCDIwMTQwMTE2ZAIBD2QWAmYPFQQ3MjAxMee6p+acrOenkeeUn+WPr+S7peWPguWKoOS4iua1t+W4gumrmOagoeWFseS6q+ivvueoiwgwMDAwMDAzMjcyMDEx57qn5pys56eR55Sf5Y+v5Lul5Y+C5Yqg5LiK5rW35biC6auY5qCh5YWx5Lqr6K++56iLCDIwMTMxMjIwZAICD2QWAmYPFQQd5Yid6YCJMjAxM+W5tDEy5pyIMTLml6XlvIDlp4sIMDAwMDAwMzEd5Yid6YCJMjAxM+W5tDEy5pyIMTLml6XlvIDlp4sIMjAxMzExMjhkAgMPZBYCZg8VBHPlhbPkuo7miJHmoKEyMDEx57qn5pys56eR55Sf5Y+C5Yqg5LiK5rW35biC6auY5qCh5YWx5Lqr6K++56iL6YCJ6K++4oCc56Gu6K6k44CB5aKe6YCJ44CB6YCA5pS56YCJ4oCd5bel5L2c55qE6YCa55+lCDAwMDAwMDMwc+WFs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b3JkZXIgYnkgcmVsZWFzZWRhdGUgZGVzYyAeDlBhcmFtZXRlclZhbHVlZBQrAQECA2RkZGIgE9UDulG9GvRO4dsU+SdCCEFM","__EVENTVALIDATION"=>"/wEWBgKY0u7vCwLT8dy8BQLG8eCkDwKuqciQCQKC3IeGDAKO8J4Nk+MLn7wUWUDvvoz1eyVjqKX9ZAs=","btnLogin"=>"登陆","txtUserID"=>$user,"txtUserPwd"=>$password,"txtValidateCode"=>$yzm);

你在 pos 页面中
$cookie_file = tempnam('./temp','cookie');
你在获取验证码程序中
$cookie_file =  $filedir."/cookie.txt";

整个过程中使用了不同的 cookie 文件,显然不能保证 cookie 是一致的
版主  我现在模拟登陆成功了,我后来发现查询成绩不需要验证码
  我只是把隐藏值也传进去了 就ok了
   但现在又有个问题   就是有时候显示成绩,有时候又是什么都没有

ivt教务管理系统