-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmainfunction.php
138 lines (132 loc) · 3.77 KB
/
mainfunction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/*
第一修改者为作者
修改者:lbr-dev,预留
修改者GITHUB:lbr-dev(https://github.com/lbr-dev/),预留
修改者QQ:lbr-dev(3170482764),预留
本项目开源地址:https://github.com/kingcardconfig/kingcardconfig/
*/
include_once('pclzip.lib.php');
function getwebpages($url, $header, $timeout){
if (substr($url,0,5)=='https') {
$opts = array('https' => array('method' => 'GET',
"protocol_version" => 1.1,
"timeout" => $timeout,
'header'=> $header));
$context = stream_context_create($opts);
$fp = fopen($url, 'r', false, $context);
$return = stream_get_contents($fp);
fclose($fp);
} else {
$opts = array('http' => array('method' => 'GET',
"protocol_version" => 1.1,
"timeout" => $timeout,
'header'=> $header));
$context = stream_context_create($opts);
$fp = fopen($url, 'r', false, $context);
$return = stream_get_contents($fp);
fclose($fp);
}
return $return;
}
function checktheproxyserver($url, $proxyip, $proxyport, $header, $timeout){
if (substr($url,0,5)=='https') {
$opts = array('https' => array('method' => 'GET',
"protocol_version" => 1.1,
"timeout" => $timeout,
'header'=> $header,
'proxy' => "tcp://".$proxyip.":".$proxyport."",
'request_fulluri' => true));
$context = stream_context_create($opts);
$fp = fopen($url, 'r', false, $context);
$return = stream_get_contents($fp);
fclose($fp);
} else {
$opts = array('http' => array('method' => 'GET',
"protocol_version" => 1.1,
"timeout" => $timeout,
'header'=> $header,
'proxy' => "tcp://".$proxyip.":".$proxyport."",
'request_fulluri' => true));
$context = stream_context_create($opts);
$fp = fopen($url, 'r', false, $context);
$return = stream_get_contents($fp);
fclose($fp);
}
return $return;
}
function gzdecodeapi($gzip) {
if (!function_exists('gzdecode')) {
function gzdecode ($data) {
$flags = ord(substr($data, 3, 1));
$headerlen = 10;
$extralen = 0;
$filenamelen = 0;
if ($flags & 4) {
$extralen = unpack('v' ,substr($data, 10, 2));
$extralen = $extralen[1];
$headerlen += 2 + $extralen;
}
if ($flags & 8) // Filename
$headerlen = strpos($data, chr(0), $headerlen) + 1;
if ($flags & 16) // Comment
$headerlen = strpos($data, chr(0), $headerlen) + 1;
if ($flags & 2) // CRC at end of file
$headerlen += 2;
$unpacked = @gzinflate(substr($data, $headerlen));
if ($unpacked === FALSE)
$unpacked = $data;
return $unpacked;
}
$return=gzdecode($gzip);
} else {
$return=gzdecode($gzip);
}
return $return;
}
function get_between($input, $start, $end) {
$substr = substr($input, strlen($start)+strpos($input, $start),(strlen($input) - strpos($input, $end))*(-1));
return $substr;
}
function wcltfapi($filename) {
$ua=$_SERVER['HTTP_USER_AGENT'];
$time=date("Y-m-d H:i:s");
$c="TIME:".$time." USER-AGENT:".$ua."";
$f=fopen($filename,"a+");
$fw=fwrite($f,$c."\n");
fclose($f);
if ($fw === false) {
$return="0";
} else {
$return="1";
}
return $return;
}
function isgziphtmlapi($isgziphtmlfilename,$html) {
file_put_contents($isgziphtmlfilename,$html);
$file = fopen($isgziphtmlfilename, "r");
//只读2字节 如果为31139则开启了gzip
$bin = fread($file, 2);
fclose($file);
$strInfo = @unpack("C2chars", $bin);
$typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
$isGzip = 0;
switch ($typeCode)
{
case 31139:
//网站开启了gzip
$isGzip = 1;
break;
default:
$isGzip = 0;
}
unlink($isgziphtmlfilename);
return $isGzip;
}
function unzip($filename){
$archive = new PclZip($filename);
if ($archive->extract() == 0) {
die("Unzip Error:".$archive->errorInfo(true));
}
}
?>