Home > Backend Development > PHP Tutorial > php Curl simulated login (particularity)_PHP tutorial

php Curl simulated login (particularity)_PHP tutorial

WBOY
Release: 2016-07-13 17:50:08
Original
897 people have browsed it

/**
* @abstract Curl simulated login
* @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 client version: 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.0rn"); 
    fwrite($sock, "Host: " . $host_url . "rn"); 
    if (!emptyempty($cookie_str)) { 
        fwrite($sock, "COOKIE: " . $cookie_str . "rn"); 
    } 
 
    fwrite($sock, "Content-type: application/x-www-form-urlencodedrn"); 
    if (!emptyempty($data)) { 
        fwrite($sock, "Content-length: " . strlen($data) . "rn"); 
    } 
    fwrite($sock, "Accept: */*rn"); 
    fwrite($sock, "rn"); 
    if (!emptyempty($data)) { 
        fwrite($sock, "$datarn"); 
    } 
    fwrite($sock, "rn"); 
    //测试文件指针是否到了文件结束的位置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的专栏

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478289.htmlTechArticle?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 -...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template