关于PHP写的投票网站之刷票终结版_PHP教程

WBOY
發布: 2016-07-13 17:16:57
原創
1044 人瀏覽過

  

  

 

  继上篇刷票风云的随笔之后,我还是决定用每个学生登录教务处的密码尝试一下,虽然这个我在开学的时候做微信开发的时候弄过。

  首先要做的是登录学校教务处网站,然后打开

<span  1</span> <span //</span><span 第一步:提交数据,生成cookie,将cookie保存在临时目录下
</span><span  2</span> <span //在指定目录中建立一个具有唯一文件名的文件。如果该目录不存在,tempnam() 会在系统临时目录中生成一个文件,并返回其文件名</span>
<span  3</span> <span $cookie_file</span>=<span tempnam</span>('./temp','cookie'<span );
</span><span  4</span> <span $ch</span>=<span curl_init();
</span><span  5</span> <span $login_url</span>="网址"<span ;
</span><span  6</span> <span $curlPost</span>="uname=账号&upwd=密码&usertypex=%B9%DC%C0%ED%D4%B1"<span ;
</span><span  7</span> curl_setopt(<span $ch</span>,CURLOPT_URL,<span $login_url</span><span );
</span><span  8</span> <span //</span><span 启用时会将头文件的信息作为数据流输出</span>
<span  9</span> curl_setopt(<span $ch</span>,CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible;MS IE 9.0; Windows NT 6.1; WOW 64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.0.30729; BRI/2; MASM; .NET4.0C; .NET4.0E; InfoPath.3; Media Center PC 6.0; SE 2.X MeTaSr 1.0)'<span );
</span><span 10</span> curl_setopt(<span $ch</span>,CURLOPT_HEADER,<span true</span><span ); 
</span><span 11</span> curl_setopt(<span $ch</span>,CURLOPT_MAXREDIRS,1<span ); 
</span><span 12</span> curl_setopt(<span $ch</span>,CURLOPT_RETURNTRANSFER,1<span );
</span><span 13</span> curl_setopt(<span $ch</span>,CURLOPT_FOLLOWLOCATION,1<span ); 
</span><span 14</span> curl_setopt(<span $ch</span>,CURLOPT_POST,1<span );
</span><span 15</span> curl_setopt(<span $ch</span>,CURLOPT_POSTFIELDS,<span $curlPost</span><span );
</span><span 16</span> <span //</span><span 设置连接结束后保存cookie信息的文件</span>
<span 17</span> curl_setopt(<span $ch</span>,CURLOPT_COOKIEJAR,<span $cookie_file</span><span );
</span><span 18</span> <span $content_login</span>=curl_exec(<span $ch</span><span );
</span><span 19</span> <span //</span><span print_r($content_login);</span>
<span 20</span> <span var_dump</span>(<span $cookie_file</span><span );
</span><span 21</span> curl_close(<span $ch</span>);
登入後複製

  测试什么都没有显示,因为:

<span $content_login</span>=curl_exec(<span $ch</span><span );
</span><span //</span><span print_r($content_login);</span>
登入後複製

  后面会解释,继续:

<span  1</span> <span $ch2</span>=<span curl_init();
</span><span  2</span> <span $login_url2</span>=网址2"<span ;
</span><span  3</span> curl_setopt(<span $ch2</span>,CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible;MS IE 9.0; Windows NT 6.1; WOW 64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.0.30729; BRI/2; MASM; .NET4.0C; .NET4.0E; InfoPath.3; Media Center PC 6.0; SE 2.X MeTaSr 1.0)'<span );
</span><span  4</span> curl_setopt(<span $ch2</span>,CURLOPT_HEADER,0<span ); 
</span><span  5</span> curl_setopt(<span $ch2</span>,CURLOPT_URL,<span $login_url2</span><span ); 
</span><span  6</span> curl_setopt(<span $ch2</span>,CURLOPT_RETURNTRANSFER,1<span );
</span><span  7</span> curl_setopt(<span $ch2</span>,CURLOPT_CONNECTTIMEOUT,120<span );
</span><span  8</span>  
<span  9</span> curl_setopt(<span $ch2</span>,CURLOPT_AUTOREFERER,1<span ); 
</span><span 10</span> curl_setopt(<span $ch2</span>,CURLOPT_POST,1<span );
</span><span 11</span> 
<span 12</span> curl_setopt(<span $ch2</span>,CURLOPT_POSTFIELDS,<span $curlPost</span><span ); 
</span><span 13</span> curl_setopt(<span $ch2</span>,CURLOPT_REFERER,"来源"<span );  
</span><span 14</span> <span //</span><span 设置连接结束后保存cookie信息的文件</span>
<span 15</span> curl_setopt(<span $ch2</span>,CURLOPT_COOKIEFILE,<span $cookie_file</span><span ); 
</span><span 16</span> <span $content_login</span>=curl_exec(<span $ch2</span><span );
</span><span 17</span> <span //</span><span $content_login='1';</span>
<span 18</span> <span print_r</span>(<span $content_login</span><span );
</span><span 19</span> <span //</span><span curl_exec($ch);</span>
<span 20</span> curl_close(<span $ch2</span>);
登入後複製

  在这里,用到的是同一个cookie,这样服务器就可以直接识别了。

<span $content_login</span>=curl_exec(<span $ch2</span>);
登入後複製

  这是获取到网页上的内容。

<span print_r</span>(<span $content_login</span>);
登入後複製

  这是将获取到的内容打印出来,如果你细心,你可以发现前面有:

<span $content_login</span>='1';
登入後複製

 

  这么一句话被我注释掉了,这是我检测是否能修改数据用的,当初在获取课表的时候就不能修改获得的数据,也不知道是为何,但是在这里可以。

  如果账号密码错了,就会按网站那样弹出个对话框显示账号密码错误,这样,只要再数据表里面再添加一项student_id便可以了,一个账号只能用一次。

  

  真心希望这次能真正的制止住刷票,我已经心疲力尽了。

  也谢谢网友们,蘑菇街的验证码真心好,我也弄出来了,明天与大家分享,但是刷票器有个功能是手工输入验证码,这又没辙了,所以放弃验证码了。

  我要被那些人骂死了。

 

  

转载请注明出处:http://www.cnblogs.com/yydcdut/p/3472248.html

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/626633.htmlTechArticle继上篇刷票风云的随笔之后,我还是决定用每个学生登录教务处的密码尝试一下,虽然这个我在开学的时候做微信开发的时候弄过。 首先要...
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板