-
Notifications
You must be signed in to change notification settings - Fork 256
/
index.php
69 lines (65 loc) · 2.35 KB
/
index.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
<?php
$post = ($_SERVER['REQUEST_METHOD']=='POST');
$headers = get_all_headers();
if(isset($headers["Origin-Url"])&&!empty($headers["Origin-Url"])){
$originUrl = urldecode($headers["Origin-Url"]);
$headerArray = array();
foreach($headers as $key => $value){
if($key=="Host" || $key=="User-Agent")
continue;
$headerArray[] = $key.":".$value;
}
$collectuseragent = "KuaiYanKanShu Spider+(+http://www.kuaiyankanshu.net/about/spider.html)";
$ch = curl_init($originUrl);
//print_r($headerArray);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, $collectuseragent);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_POST, $post);
if($post)
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
$response = curl_exec($ch);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$responseHeaders = substr($response, 0, $headerSize);
$html = substr($response, $headerSize);
curl_close($ch);
//echo $responseHeaders;
$headerArray = explode("\r\n", $responseHeaders);
$matched = false;
$charset = "utf-8";
foreach($headerArray as $header){
if(preg_match('/charset.*?([\w-]+)/i', $header, $matches)){
$charset = $matches[1];
$matched = true;
}
}
if(!$matched && preg_match('/charset.*?([\w-]+)/i', $html, $matches)){
$charset = $matches[1];
}
header( "Content-Type:text/plain; charset=".$charset);
echo $html;
}else{
header( "Content-Type:text/plain;charset=utf-8");
foreach($headers as $key => $value) {
echo "<!--$key => $value-->\r\n";
}
}
function get_all_headers() {
$headers = array();
foreach($_SERVER as $key => $value) {
if(substr($key, 0, 5) === 'HTTP_') {
$key = substr($key, 5);
$key = strtolower($key);
$key = str_replace('_', ' ', $key);
$key = ucwords($key);
$key = str_replace(' ', '-', $key);
$headers[$key] = $value;
}
}
return $headers;
}
?>