查看單個文章
  #5  
舊 2006-05-04, 02:05 AM
wmh wmh 目前離線
進階會員
 
註冊日期: 2004-08-27
文章: 310
預設

請接第一篇的程式


代碼:
// functions //

function fConnect($host, $port, $timeout) {
	if ($port == 443) $host = "ssl://$host";
	$fp = fsockopen($host, $port, $errno, $errstr, $timeout);
	if (!$fp) {
		echo "$errstr ($errno)<br />\n";
		exit();
	} else {
		return $fp;
	}
}

function fGet($fp, $host, $path, $extra) {
	$getContent = "GET $path HTTP/1.1\r\n";
	$getContent .= "Host: $host\r\n";
	$getContent .= "Accept: */*\r\n";
	$getContent .= "Accept-Language: zh-tw\r\n";
	$getContent .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)\r\n";
	$getContent .= "Connection: Keep-Alive";
	if ($extra != "") $getContent .= "\r\n$extra";
	fputs($fp, $getContent."\r\n\r\n");
}

function fPost($fp, $host, $path, $data, $extra) {
	$dataLength = strlen($data);
	$postContent = "POST $path HTTP/1.1\r\n";
	$postContent .= "Host: $host\r\n";
	$postContent .= "Content-Type: application/x-www-form-urlencoded\r\n";
	$postContent .= "Content-Length: $dataLength\r\n";
	$postContent .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)\r\n";
	$postContent .= "Connection: Keep-Alive";
	if ($extra != "") $postContent .= "\r\n$extra";
	$postContent .= "\r\n\r\n";
	$postContent .= $data;
	fputs($fp, $postContent);
}

function fContentAllTill($fp, $till) {
	$content = "";
	while (!feof($fp)) {
		@$tmp = fgets($fp, 16192);
		if ($tmp) $content .= $tmp;
		if (strstr($tmp, $till)) break;
	}
	return $content;
}

function parseCPAT($content) {
	if (preg_match("/CP_AT=([^;]{20,40});/", $content, $tmp)) {
		return $tmp[1];
	}
	return null;
}

function parseCookies($content) {
	$rtn = "";
	while (preg_match("/Set-Cookie: (.*)\r/", $content, $tmp)) {
		if ($rtn != "") $rtn .= "\r\n";
		$rtn .= "Cookie: {$tmp[1]}";
		$content = str_replace($tmp[0], "", $content);
	}
	return $rtn;
}

function parseInitialPassword($content) {
	if (preg_match("/<input type=\"hidden\" name=\"initialPassword\" value=\"(.{6})\">/", $content, $tmp)) {
		return $tmp[1];
	}
	return null;
}

?>
DONE!
回覆時引用此篇文章