post.php
<?php
$cfg = array (
// 用户名
name=>"xdy108@126.com",
// 密码
pass=>"001002",
cookie_file=>"cookie.txt"
);
include("httpd.php");
$c = new http("login.kaixin.com", "/Login.do", "POST");
$c->set_val("email", $cfg["name"]);
$c->set_val("password", $cfg["pass"]);
$c->set_val("login_type", "1000");
$c->set_val("autoLogin", "true");
$c->set_val("origURL", "http://www.kaixin.com/SysHome.do");
$c->send();
$source = $c->get_cnt(true);
$s_regex = '@(societyguester=\w+;)@s';
$a_matches = array ();
preg_match_all($s_regex, $source, $a_matches);
$cookie_login_key = $a_matches[1][1];//cookie放入这个变量
$c2 = new http("gf.kaixin.com", "/bank.do", "POST", 80, $cookie_login_key);
$c2->send();
$source = $c2->get_cnt();
echo $source;
exit;
?>
httpd.php
在一个项目里摘录出来的:
<?php
$post = '';
while (list($k,$v) = each($comment)) {
$post .= rawurlencode($k)."=".rawurlencode($v)."&";
}
$post = substr( $post , 0 , -1 );
$len = strlen($post);
$file = "/interface/commentpost";
$fp = @fsockopen( $host , 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)\n";die;
} else {
$receive = '';
$out = "POST $file HTTP/1.0\r\n";
$out .= "Host: $host\r\n";
$out .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.8\r\n";
$out .= "Accept-Language: zh-cn,zh;q=0.5\r\n";
$out .= "Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7\r\n";
//$out .= "Keep-Alive: 300\r\n";
$out .= "Content-type: application/x-www-form-urlencoded\r\n";
$out .= "Connection: Close\r\n";
$out .= "Content-Length: $len\r\n";
$out .="\r\n";
$out .= $post."\r\n";
fwrite($fp, $out);
$line = fgets($fp,1024);
while (!feof($fp)) {
$receive .= fgets($fp, 128);
}
fclose($fp);
}
//echo $receive;
$receive = explode("\r\n\r\n",$receive);
$receive = $receive[1];
//echo $receive;
return json_decode($receive);
?>
<?php
$cfg = array (
// 用户名
name=>"xdy108@126.com",
// 密码
pass=>"001002",
cookie_file=>"cookie.txt"
);
include("httpd.php");
$c = new http("login.kaixin.com", "/Login.do", "POST");
$c->set_val("email", $cfg["name"]);
$c->set_val("password", $cfg["pass"]);
$c->set_val("login_type", "1000");
$c->set_val("autoLogin", "true");
$c->set_val("origURL", "http://www.kaixin.com/SysHome.do");
$c->send();
$source = $c->get_cnt(true);
$s_regex = '@(societyguester=\w+;)@s';
$a_matches = array ();
preg_match_all($s_regex, $source, $a_matches);
$cookie_login_key = $a_matches[1][1];//cookie放入这个变量
$c2 = new http("gf.kaixin.com", "/bank.do", "POST", 80, $cookie_login_key);
$c2->send();
$source = $c2->get_cnt();
echo $source;
exit;
?>
httpd.php
<?php
class http
{
var $host;
var $port;
var $method;
var $url;
var $errno;
var $errstr;
var $key;
var $fp;
var $cnt;
var $isok;
function http($host, $url, $method = "GET", $port = 80, $cookie = "", $referer = "")
{
$this->host = $host;
$this->port = $port;
$this->method = $method;
$this->url = $url;
$this->cookie = $cookie;
$this->referer = $referer;
$this->cnt = "";
$this->key = array ();
$this->fp = false;
$this->isok = true;
$this->debug = false;
}
function send()
{
$this->cnt = "";
$this->_connect();
if (!$this->isok)
{
return false;
}
$tmp = array ();
$d = "";
foreach ($this->key as $n=>$v)
{
$tmp[] = $n."=".$v;
}
$d = implode("&", $tmp);
if ($this->method == "GET")
{
if ($d != "")
{
fwrite($this->fp, $this->method." ".$this->url."?".$d." HTTP/1.0\r\n");
}
else
{
fwrite($this->fp, $this->method." ".$this->url." HTTP/1.0\r\n");
}
}
else
{
fwrite($this->fp, $this->method." ".$this->url." HTTP/1.0\r\n");
fwrite($this->fp, "Content-Length: ".strlen($d)."\r\n");
fwrite($this->fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fwrite($this->fp, "Cookie: ".$this->cookie."\r\n");
fwrite($this->fp, "Referer: ".$this->referer."\r\n");
}
fwrite($this->fp, "Host: ".$this->host."\r\n\r\n");
if ($this->method == "POST")
{
fwrite($this->fp, $d);
}
while (!feof($this->fp))
{
$this->cnt .= fgets($this->fp, 2048);
}
fclose($this->fp);
}
function set_val($n, $v)
{
$this->key[$n] = rawurlencode($v);
}
function get_val($n)
{
parse_str($this->get_cnt());
return ${$n
}
;
}
function get_cnt($type = false)
{
if ($type == false)
{
return substr($this->cnt, strpos($this->cnt, "\r\n\r\n")+4);
}
else
{
return $this->cnt;
}
}
function errmsg($msg)
{
$this->isok = false;
if ($this->debug)
{
echo $msg;
}
return false;
}
function _connect()
{
$this->fp = fsockopen($this->host, $this->port, $this->errno, $this->errstr, 30);
if (!$this->fp)
{
return $this->errmsg($this->errstr);
}
else
{
$this->isok = true;
}
}
}
?>
class http
{
var $host;
var $port;
var $method;
var $url;
var $errno;
var $errstr;
var $key;
var $fp;
var $cnt;
var $isok;
function http($host, $url, $method = "GET", $port = 80, $cookie = "", $referer = "")
{
$this->host = $host;
$this->port = $port;
$this->method = $method;
$this->url = $url;
$this->cookie = $cookie;
$this->referer = $referer;
$this->cnt = "";
$this->key = array ();
$this->fp = false;
$this->isok = true;
$this->debug = false;
}
function send()
{
$this->cnt = "";
$this->_connect();
if (!$this->isok)
{
return false;
}
$tmp = array ();
$d = "";
foreach ($this->key as $n=>$v)
{
$tmp[] = $n."=".$v;
}
$d = implode("&", $tmp);
if ($this->method == "GET")
{
if ($d != "")
{
fwrite($this->fp, $this->method." ".$this->url."?".$d." HTTP/1.0\r\n");
}
else
{
fwrite($this->fp, $this->method." ".$this->url." HTTP/1.0\r\n");
}
}
else
{
fwrite($this->fp, $this->method." ".$this->url." HTTP/1.0\r\n");
fwrite($this->fp, "Content-Length: ".strlen($d)."\r\n");
fwrite($this->fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fwrite($this->fp, "Cookie: ".$this->cookie."\r\n");
fwrite($this->fp, "Referer: ".$this->referer."\r\n");
}
fwrite($this->fp, "Host: ".$this->host."\r\n\r\n");
if ($this->method == "POST")
{
fwrite($this->fp, $d);
}
while (!feof($this->fp))
{
$this->cnt .= fgets($this->fp, 2048);
}
fclose($this->fp);
}
function set_val($n, $v)
{
$this->key[$n] = rawurlencode($v);
}
function get_val($n)
{
parse_str($this->get_cnt());
return ${$n
}
;
}
function get_cnt($type = false)
{
if ($type == false)
{
return substr($this->cnt, strpos($this->cnt, "\r\n\r\n")+4);
}
else
{
return $this->cnt;
}
}
function errmsg($msg)
{
$this->isok = false;
if ($this->debug)
{
echo $msg;
}
return false;
}
function _connect()
{
$this->fp = fsockopen($this->host, $this->port, $this->errno, $this->errstr, 30);
if (!$this->fp)
{
return $this->errmsg($this->errstr);
}
else
{
$this->isok = true;
}
}
}
?>
在一个项目里摘录出来的:
<?php
$post = '';
while (list($k,$v) = each($comment)) {
$post .= rawurlencode($k)."=".rawurlencode($v)."&";
}
$post = substr( $post , 0 , -1 );
$len = strlen($post);
$file = "/interface/commentpost";
$fp = @fsockopen( $host , 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)\n";die;
} else {
$receive = '';
$out = "POST $file HTTP/1.0\r\n";
$out .= "Host: $host\r\n";
$out .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.8\r\n";
$out .= "Accept-Language: zh-cn,zh;q=0.5\r\n";
$out .= "Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7\r\n";
//$out .= "Keep-Alive: 300\r\n";
$out .= "Content-type: application/x-www-form-urlencoded\r\n";
$out .= "Connection: Close\r\n";
$out .= "Content-Length: $len\r\n";
$out .="\r\n";
$out .= $post."\r\n";
fwrite($fp, $out);
$line = fgets($fp,1024);
while (!feof($fp)) {
$receive .= fgets($fp, 128);
}
fclose($fp);
}
//echo $receive;
$receive = explode("\r\n\r\n",$receive);
$receive = $receive[1];
//echo $receive;
return json_decode($receive);
?>
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/1447/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2013-1-21 16:12
代码里没一个注释!多不好啊!这个变量名也看不明白是什么意思!要注意哦!