Upload 66668888.php
Browse files- 66668888.php +87 -0
66668888.php
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
error_reporting(0);
|
3 |
+
// 这行代码用于关闭输出缓冲。关闭后,脚本的输出将立即发送到浏览器,而不是等待缓冲区填满或脚本执行完毕。
|
4 |
+
ini_set('output_buffering', 'off');
|
5 |
+
|
6 |
+
// 这行代码禁用了 zlib 压缩。通常情况下,启用 zlib 压缩可以减小发送到浏览器的数据量,但对于服务器发送事件来说,实时性更重要,因此需要禁用压缩。
|
7 |
+
ini_set('zlib.output_compression', false);
|
8 |
+
|
9 |
+
// 这行代码使用循环来清空所有当前激活的输出缓冲区。ob_end_flush() 函数会刷新并关闭最内层的输出缓冲区,@ 符号用于抑制可能出现的错误或警告。
|
10 |
+
while (@ob_end_flush()) {}
|
11 |
+
// 这行代码设置 HTTP 响应的自定义头部 X-Accel-Buffering 为 no,用于禁用某些代理或 Web 服务器(如 Nginx)的缓冲。
|
12 |
+
// 这有助于确保服务器发送事件在传输过程中不会受到缓冲影响。
|
13 |
+
header('X-Accel-Buffering: no');
|
14 |
+
|
15 |
+
$url = 'https://api.openai.com/';
|
16 |
+
$url = rtrim($url, '/');
|
17 |
+
$headers = getallheaders();
|
18 |
+
unset($headers['Host']);
|
19 |
+
unset($headers['Content-Length']);
|
20 |
+
$headers['Connection'] = 'close';
|
21 |
+
$headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36';
|
22 |
+
$targetHeaders = [];
|
23 |
+
foreach ($headers as $key => $value) {
|
24 |
+
if ($key !== 'Host' && $key !== 'Content-Length') {
|
25 |
+
$targetHeaders[] .= ($key . ': ' . $value);
|
26 |
+
}
|
27 |
+
}
|
28 |
+
|
29 |
+
header('Access-Control-Allow-Headers: *');
|
30 |
+
header('Access-Control-Allow-Origin: *');
|
31 |
+
header('Access-Control-Allow-Methods: *');
|
32 |
+
header('Access-Control-Max-Age: 86400');
|
33 |
+
|
34 |
+
if($_SERVER['REQUEST_METHOD'] === "OPTIONS"){
|
35 |
+
exit();
|
36 |
+
}
|
37 |
+
|
38 |
+
|
39 |
+
$options = array(
|
40 |
+
'http' => array(
|
41 |
+
/* 'proxy' => 'tcp://127.0.0.1:7890',
|
42 |
+
'request_fulluri' => true, */
|
43 |
+
'method' => $_SERVER['REQUEST_METHOD'],
|
44 |
+
'header' => $targetHeaders,
|
45 |
+
'content' => file_get_contents('php://input'),
|
46 |
+
'ignore_errors' => true
|
47 |
+
),
|
48 |
+
'ssl' => array(
|
49 |
+
'verify_peer' => false,
|
50 |
+
'verify_peer_name' => false
|
51 |
+
)
|
52 |
+
);
|
53 |
+
|
54 |
+
$context = stream_context_create($options);
|
55 |
+
//$stream = fopen($url . ($_SERVER['PATH_INFO']?$_SERVER['PATH_INFO']:''/*$_SERVER['REQUEST_URI']*/), 'r', false, $context);
|
56 |
+
if(preg_match('/(https?):\/\/?(.*?$)/', $_SERVER['REQUEST_URI'], $mc)){
|
57 |
+
if(count($mc)>2){
|
58 |
+
$url = $mc[1]. '://' .$mc[2];
|
59 |
+
}
|
60 |
+
} else {
|
61 |
+
echo "URL不正确";
|
62 |
+
exit();
|
63 |
+
}
|
64 |
+
|
65 |
+
$stream = fopen($url , 'r', false, $context);
|
66 |
+
|
67 |
+
|
68 |
+
$responseHeaders = [];
|
69 |
+
foreach ($http_response_header as $header) {
|
70 |
+
$headerParts = explode(':', $header, 2);
|
71 |
+
if (count($headerParts) == 2) {
|
72 |
+
$responseHeaders[trim($headerParts[0])] = trim($headerParts[1]);
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
http_response_code(intval(substr($http_response_header[0],9,3)));
|
77 |
+
foreach ($responseHeaders as $name => $value) {
|
78 |
+
if(stripos($name, "access-control-") !== 0)
|
79 |
+
header(str_replace("\r\n", "", $name . ': ' . $value));
|
80 |
+
}
|
81 |
+
|
82 |
+
|
83 |
+
$output = fopen('php://output', 'w');
|
84 |
+
|
85 |
+
stream_copy_to_stream($stream, $output);
|
86 |
+
fclose($stream);
|
87 |
+
fclose($output);
|