本文实例讲述了php curl实现模拟登陆并上传文件操作。分享给大家供大家参考,具体如下:
<?phpheader('content-type:text/html;chart=gb2312');//要注意你需要上传的网站服务器的运行环境,还要看它的请求是否被压缩和转码还有就是//在框架中或者说php5.3以下的版本可以用@,但是其它的就只能用new curlfile()函数来转化文件了//注意你要发送的服务器的header头的结构和特殊参数,实在不行就自己构建一个。废话不多说,直接上代码。function curl_form($post_data,$sumbit_url,$http_url,$cookie_file){ $headers = array(); $headers[] = 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'; $headers[] = 'cache-control: max-age=0'; $headers[] = 'accept-encoding: gzip, deflate'; $headers[] = 'origin: http://my.***.com'; $headers[] = 'accept-language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3'; $headers[] = 'upgrade-incure-requests: 1'; $headers[] = 'content-type: application/x-www-form-urlencoded'; $headers[] = 'ur-agent: mozilla/5.0 (x11; ubuntu; linux i686; rv:28.0) gecko/20100101 firefox/28.0'; $headers[] = 'connection: keep-alive';// $headers[] = 睡眠规律'cookie: aspssionidcctctqqc=kbglpdkbikdidcbgfoknmkoe'; //初始化 $ch = curl_init(); //设置变量 curl_topt($ch, curlopt_url, $sumbit_url); curl_topt($ch, curlopt_httpheader, $headers); curl_topt($ch, curlopt_cookiefile, $cookie_file); curl_topt($ch, curlopt_returntransfer, 1);//执行结果是否被返回,0是返回,1是不返回 curl_topt($ch, curlopt_header, 0);//参数设置,是否显示头部信息,1为显示,0为不显示 curl_topt($ch, curlopt_referer, $http_url); //表单数据,是正规的表单设置值为非0 curl_topt($ch, curlopt_post, 1); curl_topt($ch, curlopt_timeout, 30); curl_topt($ch,curlopt_proxy,'127.0.0.1:8888');// curl_topt($ch, curlopt_encoding, "");// curl_topt($ch, curlopt_encoding, 'gzip,deflate'); curl_topt($ch, curlopt_天气气压postfields, http_build_query($post_data)); //执行并获取结果 $output = curl_exec($ch); if($output === fal) { echo "<br/>","curl美舍雅阁化妆品 error:".curl_error($ch); }el{ return $outphour怎么读ut; } // 释放curl句柄 curl_clo($ch);}$temp = array();$temp['title'] = iconv( "utf-8", "gb2312//ignore" , "牛排店加盟");$temp['ly'] = iconv( "utf-8", "gb2312//ignore" , "特色餐饮加盟");$temp['classid'] = iconv( "utf-8", "gb2312//ignore" , "7159");$temp['newssort'] = iconv( "utf-8", "gb2312//ignore" , "1");$temp['panduan'] = iconv( "utf-8", "gb2312//ignore" , "0");$temp['submit_button'] = iconv( "utf-8", "gb2312//ignore" , "发布");$temp['addr'] = iconv( "utf-8", "gb2312//ignore" , "bjcanyin");$temp['contentbg'] = "";$temp['newss'] = iconv( "utf-8", "gb2312//ignore" , htmlspecialchars_decode("<p>阿会计师的贺卡收到框架</p><p><img alt=\"\" src=\" http://localhost/super/uploads/img/2017-08-10/598c145a9527e.jpg\" style=\"height:243px; width:324px\" /></p>", ent_quotes));$cookie_file = dirname(__file__)."/jdzj.tmp";$sumbit_url = "http://***/news/***.as开心大冒险电影p";$http_url="http://***/news/***.asp?act=addok";$img = curl_form($temp,$http_url,$sumbit_url,$cookie_file);var_dump($img);
ps:关于php curl选项详细说明可参考
本文发布于:2023-04-08 03:56:03,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/95b85ae3aa3c8896af610b99719604c4.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:PHP CURL实现模拟登陆并上传文件操作示例.doc
本文 PDF 下载地址:PHP CURL实现模拟登陆并上传文件操作示例.pdf
留言与评论(共有 0 条评论) |