通过php请求实现的登陆
<?php /** * Created by PhpStorm. * User: 意灵魔法馆 * Date: 2016/5/24 0024 * Time: 下午 17:07 */ //开始之前做几点说明,首先你得知道用户名和密码因为是模拟浏览器行为实现登陆,浏览器在请求也需要用户数据才能跳转到其他页面 //初始curl资源 $curl = curl_init(); //配置 curl_setopt($curl, CURLOPT_URL, 'www.tang.com/blog/admin/user.php?a=check'); curl_setopt($curl, CURLOPT_USERAGENT, 'TANG'); curl_setopt($curl, CURLOPT_REFERER, 'blog/admin/user.php'); $data = array( 'username' => 'tangshuai', 'password' => 'tangshuai', 'captcha' => '' ); $data_str = http_build_query($data); $header[] = 'Accept:text/html'; $header[] = 'Accept-Language:zh-CN'; $header[] = 'Connection:close'; //设置cookie存储的地址 $cookie_address = 'E:/tangdengshuai/Apache24/htdocs/myweb3/cookie'; curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_address); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $data_str); curl_setopt($curl, CURLOPT_HEADER, $header); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //发出请求 $response = curl_exec($curl); echo iconv('utf-8', 'gbk', $response); //关闭资源 curl_close($curl); //初始化curl资源 $curl=curl_init(); // //请求时携带cookie $cookie_address='E:/tangdengshuai/Apache24/htdocs/myweb3/cookie'; curl_setopt($curl,CURLOPT_COOKIEFILE,$cookie_address); //配置get请求所需的数据 curl_setopt($curl,CURLOPT_URL,'www.tang.com/blog/admin/index.php'); //配置请求代理端的数据 curl_setopt($curl,CURLOPT_USERAGENT,'TANG'); //配置请求来源 curl_setopt($curl,CURLOPT_REFERER,'www.tang.com/blog'); //额外的请求头信息 $header[]='Accept:text/html'; $header[]='Accept-Language:zh-CN'; $header[]='Connection:close'; curl_setopt($curl,CURLOPT_HEADER,$header); //将头部当输出内容 curl_setopt($curl,CURLOPT_HEADER,true); //不直接输出内容 curl_setopt($curl,CURLOPT_RETURNTRANSFER,true); //发送请求 $response=curl_exec($curl); echo iconv('utf-8','gbk',$response); //关闭curl资源 curl_close($curl);
一萧一剑走江湖,一笑一乐看世界,一切美好的事物我们都需要去用心感受,聆听自然给予我们的欢乐.
小时候觉得长大了多好,可以到外面的世界看一看,可长大了,却向往童年般的生活,没有烦恼,该哭的时候哭,该笑的时候笑,想做什么都可以.即便我们长大了更应该热爱生活懂得爱自己,不要抱怨生活对你的不公,开心的活着比什么都好。
所以在这个有限的时间里,我们需要快乐高兴的活着,活出属于自己的青春.忘记那些不痛快的事情.我们需要梦想来使得我们的人生更有意义.
今天就分享到这里吧,大家可以叫我一萧,可能在以后的日子里,我分享的不仅仅是代码上的事情,因为能让我们感到快乐和高兴并且获得收获的不仅仅是技术层面上的,应该有很多很多