php Curl模拟登陆(特殊性)
发布时间:2014-09-05 11:07:01作者:知识屋
<?php
/**
* @abstract Curl模拟登陆
* @version Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
MySQL 客户端版本: mysqlnd 5.0.7-dev - 091210 - $Revision: 304625 $
* time 2012-04-17
* @author Veric
* @copyright
*/
function getCookieUrl($host_url, $script_name, $method = 'GET', $data = '', $cookie_str = ''){
$sock = fsockopen($host_url, 80, $errno, $errstr, 30);
if (!$sock) die("$errstr ($errno)/n");
//将字符串转化为大写strToUpper
$method = strToUpper($method);
$method = ($method == 'GET') ? 'GET' : 'POST';
if (substr($script_name, 0, 1) != '/') {
$script_name = '/' . $script_name;
}
//写入文件
fwrite($sock, $method . " " . $script_name . " HTTP/1.0/r/n");
fwrite($sock, "Host: " . $host_url . "/r/n");
if (!emptyempty($cookie_str)) {
fwrite($sock, "COOKIE: " . $cookie_str . "/r/n");
}
fwrite($sock, "Content-type: application/x-www-form-urlencoded/r/n");
if (!emptyempty($data)) {
fwrite($sock, "Content-length: " . strlen($data) . "/r/n");
}
fwrite($sock, "Accept: */*/r/n");
fwrite($sock, "/r/n");
if (!emptyempty($data)) {
fwrite($sock, "$data/r/n");
}
fwrite($sock, "/r/n");
//测试文件指针是否到了文件结束的位置feof
//从文件指针中读取一行fgets
$body = "";
while (!feof($sock)) {
$body .= fgets($sock, 4096);
}
fclose($sock);
return $body;
}
$_SESSION[num]=$num=616343;
$host_url = 'www.*******.com';
$host_page='space.php?uid='.$num.'&ticket=';
$data ='';
//获取$cookie 是用网络嗅探器抓取的 分析数据包 可自行下载
$cookie='hyr_recommenduser=24; hyr_viewuids=476346__359336_154171_86276_300199_386764_380537_45907_297250; __utmc=169110968; hyr_auth=d4c7DUAeTbdnIkgqwKJLN78W7YDhUA%2FLr0y6Ssyo9ja0c5D0o7VYCPW8rYiSl6S%2F%2FLJJWYCsVElX6ImSxclFSb2fJdM; hyr_loginuser=kongbo; hyr_xy=0; __utma=169110968.1584085828.1331304385.1331304385.1331304385.1; __utmb=169110968.1.10.1331304385; __utmz=169110968.1331304385.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); hyr_sendmail=1; hyr_synfriend=1; _jkb_9202=1; _webim=%7B%22o%22%3Afalse%2C%22s%22%3A%22available%22%7D
';
echo $content1= getCookieUrl($host_url, $host_page , 'POST', $data, $cookie);
?>
摘自 Vericlongmore的专栏
(免责声明:文章内容如涉及作品内容、版权和其它问题,请及时与我们联系,我们将在第一时间删除内容,文章内容仅供参考)