//获取cookie信息 public function get_cookie(){ header("Content-Type: text/html;charset=utf-8"); $url = 'http://signin.aliyun.com/login.htm'; //url地址 $post = "user_principal_name=***@***.onaliyun.com&password_ims=*****"; //POST数据 $ch = curl_init($url); //初始化 curl_setopt($ch,CURLOPT_HEADER,1); //将头文件的信息做为数据流输出 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); //返回获取的输出文本流 curl_setopt($ch,CURLOPT_POSTFIELDS,$post); //发送POST数据 $content = curl_exec($ch); //执行curl并赋值给$content file_put_contents(dirname(__FILE__).'\cookie.txt',$content); curl_close($ch); //关闭curl $this->use_cookie(); }
//利用获取到的cookie信息模拟登陆 public function use_cookie(){ $cookie=file_get_contents(dirname(__FILE__).'\cookie.txt'); //GetBetween():截取字符串中间的字符(我有在随笔中单独分享过此方法) $local=$this->GetBetween($cookie,'Location:','Server:'); header("location:$local"); //直接跳转至登陆成功页面 }