博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php模拟post提交数据,用处很多,可用来网站的采集,登陆等等
阅读量:7044 次
发布时间:2019-06-28

本文共 1589 字,大约阅读时间需要 5 分钟。

1. [代码][PHP]代码     

array('user_login' => $user_login, 'password' => $password, '_wp_http_referer' => '/bbpress/', 're' => '', 'remember' => true)); foreach ($argv['cookie'] as $key => $value) { $params[] = $key . '=' . $value; } $params = implode('&', $params); $header = "POST /bbpress/bb-login.php HTTP/1.1\r\n"; $header .= "Host:$host:$port\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($params) . "\r\n"; $header .= "Connection: Close\r\n\r\n"; $header .= $params; $fp = fsockopen($host, $port); fputs($fp, $header); while (!feof($fp)) { $str = fgets($fp); //以下是自己的逻辑代码,这里主要是模拟cookie,可用来同步登陆 if (!(strpos($str, "Set-Cookie:") === false)) { $tmparray = explode(" ", $str); $cookiearray = explode("=", $tmparray[1]); $cookiepaths = explode("=", $tmparray[6]); $cookiename = urldecode($cookiearray[0]); $cookievalue = urldecode(substr($cookiearray[1], 0, strlen($cookiearray[1]) - 1)); $cookietime = time() + 3600 * 24 * 7; $cookiepath = urldecode(substr($cookiepaths[1], 0, strlen($cookiepaths[1]) - 1)); setcookie($cookiename, $cookievalue, $cookietime, $cookiepath); } } fclose($fp);}?>

2. [代码][PHP]代码    

array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded' . '\r\n'.'User-Agent : Jimmy\'s POST Example beta' . '\r\n'.'Content-length:' . strlen($post_string) + 8, 'content' => 'mypost=' . $post_string) ); $stream_context = stream_context_create($context); $data = file_get_contents($remote_server, false, $stream_context); return $data;} ?>

转载地址:http://ssqal.baihongyu.com/

你可能感兴趣的文章
友达光电(昆山)第六代LTPS液晶面板厂 成功点亮首片5.5吋Full HD面板 缔造最快速量产记录 展现领先LTPS技术实力...
查看>>
Chrome 暗黑模式最新进展:现在可自动跟随系统主题设置
查看>>
Event Loop是个什么玩意:从 Vue 的 nextTick 说起
查看>>
前PS VR伦敦团队另立门户,创立新的VR工作室
查看>>
jSearch(聚搜) v0.5.0 发布,多项更新和体验优化
查看>>
日志收集(ElasticSearch)串联查询 MDC
查看>>
5.For loops
查看>>
抛砖引玉之~sftp
查看>>
linux mysql 操作命令
查看>>
[20180126]内核参数tcp_keepalive.txt
查看>>
Leetcode打卡 | No.016 最接近的三数之和
查看>>
9.数据库服务器部署之------3步实现远程访问
查看>>
Nginx服务器开箱体验
查看>>
华虹宏力探索智能制造 亚信安全洞察全网风险
查看>>
在PyODPS DataFrame自定义函数中使用pandas、scipy和scikit-learn
查看>>
无人机为何“一夜爆红”?开源飞控在其后助力
查看>>
LG有意进军自动驾驶领域, 或开发基于3D摄像头的安全驾驶辅助系统
查看>>
Android项目实战(十九):Android Studio 优秀插件: Parcelable Code Generator
查看>>
Linux启动/停止/重启Mysql数据库的方法
查看>>
Ubuntu 16.04安装SQLite Browser操作SQLite数据库
查看>>