-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.php
146 lines (145 loc) · 3.37 KB
/
global.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
139
140
141
142
143
144
145
146
<?php
function get($url, $cj, $timeout = 5, $referer = "" ){
switch($cj){
case "curl_init":
$ch = curl_init($url);
$user_agent = "Baiduspider+(+http://www.baidu.com/search/spider.htm)";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.baidu.com");
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$data = curl_exec($ch);
curl_close($ch);
return $data;
break;
case "file_get_contents":
for($i=0;$i<3;$i++){
$data = @file_get_contents($url);
if($data) break;
}
return $data;
break;
case "fsock":
$bits = @parse_url( $url );
if ( !$bits[host] )
{
return "";
}
if ( $bits[port] )
{
$port = intval( $bits[port] );
}
else
{
$port = $bits[scheme] == "https" ? 443 : 80;
}
$portq = $port == 80 ? "" : ":{$port}";
$stime = time( );
$fp = @fsockopen( $bits[host], $port, $errno, $errstr, $timeout );
if ( !$fp )
{
return "";
}
else
{
$stime = time( ) - $stime;
$timeout = $timeout - $stime;
if ( $timeout < 1 )
{
$timeout = 1;
}
stream_set_timeout( $fp, $timeout );
if ( !$referer )
{
$referer = $bits[scheme]."://".$bits[host]."/";
}
$path = $bits[path] ? $bits[path] : "/";
if ( $bits[query] )
{
$path .= "?".$bits[query];
}
$out = "GET {$path} HTTP/1.0\r\n";
$out .= "Host: {$bits[host]}{$portq}\r\n";
$out .= "User-Agent: Baiduspider+(+http://www.baidu.com/search/spider.htm)\r\n";
$out .= "Accept: */*\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "Accept-Encoding: identity\r\n";
$out .= "Referer: http://www.baidu.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fputs( $fp, $out );
$data = "";
$inHeaders = TRUE;
while ( $line = @fgets( $fp, 2048 ) )
{
if ( $inHeaders )
{
$line = trim( $line );
if ( empty( $line ) )
{
$inHeaders = FALSE;
}
continue;
}
$data .= $line;
}
fclose( $fp );
return $data;
}
case "pfsock":
$bits = @parse_url ( $url );
if (! $bits [host]) {
return "";
}
if ($bits [port]) {
$port = intval ( $bits [port] );
} else {
$port = $bits [scheme] == "https" ? 443 : 80;
}
$portq = $port == 80 ? "" : ":{$port}";
$stime = time ();
$fp = @pfsockopen ( $bits [host], $port, $errno, $errstr, $timeout );
if (! $fp) {
return "";
} else {
$stime = time () - $stime;
$timeout = $timeout - $stime;
if ($timeout < 1) {
$timeout = 1;
}
stream_set_timeout ( $fp, $timeout );
if (! $referer) {
$referer = $bits [scheme] . "://" . $bits [host] . "/";
}
$path = $bits [path] ? $bits [path] : "/";
if ($bits [query]) {
$path .= "?" . $bits [query];
}
$out = "GET {$path} HTTP/1.0\r\n";
$out .= "Host: {$bits[host]}{$portq}\r\n";
$out .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n";
$out .= "Accept: *//*\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "Accept-Encoding: identity\r\n";
$out .= "Referer: {$referer}\r\n";
$out .= "Connection: Close\r\n\r\n";
fputs ( $fp, $out );
$data = "";
$inHeaders = TRUE;
while ( $line = @fgets ( $fp, 2048 ) ) {
if ($inHeaders) {
$line = trim ( $line );
if (empty ( $line )) {
$inHeaders = FALSE;
}
continue;
}
$data .= $line;
}
fclose ( $fp );
}
return $data;
break;
}
}
?>