登陆页代码
<?php require './Snoopy.class.php'; $snoopy=new Snoopy(); $snoopy->fetch("http://localhost:8095/?g=admin&m=index&a=verify_code&t=".time()); preg_match('/PHPSESSID=([\w]+);/', $snoopy->headers[4],$sessionid); $jsessionid=$sessionid[1]; $imgcode=base64_encode($snoopy->results); ?> <form method="post" action="send.php"> 用户名:<input class="text user" type="text" name="username" id="username" /><br /> 密码:<input class="text pass" type="password" name="password" id="password" /><br /> 验证码:<input class="text vifity" type="text" name="verify_code" id="verify_code" /><img alt="" src="data:image/gif;base64,<?php echo $imgcode?>" /><br /> <input type="hidden" name="sessionid" value="<?php echo $jsessionid;?>" /> <input type="submit" name="submit" value="登陆" /> </form>发布页代码
<?php require './Snoopy.class.php'; $snoopy=new Snoopy(); $submit['username']=$_POST['username']; $submit['password']=$_POST['password']; $submit['verify_code']=$_POST['verify_code']; $snoopy->agent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; InfoPath.2; MAXTHON 2.0)"; $add_url="http://localhost:8095/?g=admin&m=index&a=login"; $referer="http://localhost:8095"; $snoopy->referer=$referer; $snoopy->cookies['PHPSESSID']=$_POST['sessionid']; if ($snoopy->submit($add_url,$submit)) { //登陆成功,获取发布页 $snoopy->setcookies(); $cookies = $snoopy->cookies; $snoopy->fetch("http://localhost:8095/?g=admin&m=item&a=add&menuid=249"); $snoopy->setcookies(); $cookies = $snoopy->cookies; $add_url="http://localhost:8095/?g=admin&m=item&a=add"; $snoopy->referer=$referer; $snoopy->cookies=$cookies; $items=array(); $cate=array("334","335","336","337","338","339","340","341","342","343","344","345","346","347","348","349"); $items['cate_id']=$cate[rand(0,count($cate))]; $items['title']='这个是标题'; $items['title_key']='zhegeshibiaoti'; $items['intro']='这个是介绍'; $items['content']='这个是内容'; $items['orig_id']=4; $items['auid']=1; $files['img']="head.jpg"; $snoopy->set_submit_multipart(); if ($snoopy->submit($add_url,$items,$files)) { } print_r($snoopy->results); exit; } else { exit('登陆失败,'.$snoopy->error); }用来给我的网站发布数据用,免得一条一条更新,好麻烦的。
------------正 文 已 结 束, 感 谢 您 的 阅 读 (折雨的天空)--------------------
转载请注明本文标题和链接:《我的模拟登陆并发表内容的代码记录》
发表评论