/**
* PanDownload 网页复刻版,PHP 语言版函数文件
*
* 务必要保证此文件存在,否则整个服务将会不可使用!
*
* 请勿随意修改此文件!如需更改相关配置请到 config.php !
*
* @version 1.3.6
*
* @author Yuan_Tuo
* @link https://imwcr.cn/
* @link https://space.bilibili.com/88197958
*
* @author LC
* @link https://lcwebsite.cn/
* @link https://space.bilibili.com/52618445
*/
if (!defined('init')){ // 直接访问处理程序
http_response_code(403); header('Content-Type: text/plain; charset=utf-8'); header('Refresh: 3;url=./'); define('init', true);
if (file_exists('config.php')) {
require('config.php');
die("HTTP 403 禁止访问!\r\n此文件是 PanDownload 网页复刻版 PHP 语言版项目版本 " . programVersion . " 的有关文件!\r\n禁止直接访问!");
} else {
http_response_code(503); header('Refresh: 5;url=https://github.com/yuantuo666/baiduwp-php');
die("HTTP 503 服务不可用!\r\n缺少相关配置和定义文件!无法正常运行程序!\r\n请重新 Clone 项目并配置!\r\n将在五秒内跳转到 GitHub 储存库!");
}
}
// main
function setCurl(&$ch, array $header) { // 批处理 curl
$a = curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 忽略证书
$b = curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // 不检查证书与域名是否匹配(2为检查)
$c = curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 以字符串返回结果而非输出
$d = curl_setopt($ch, CURLOPT_HTTPHEADER, $header); // 请求头
return($a&&$b&&$c&&$d);
}
function post(string $url, $data, array $header) { // POST 发送数据
$ch = curl_init($url);
setCurl($ch, $header);
curl_setopt($ch, CURLOPT_POST, true); // POST 方法
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // POST 的数据
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function get(string $url, array $header) { // GET 请求数据
$ch = curl_init($url);
setCurl($ch, $header);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function head(string $url, array $header) { // 获取响应头
$ch = curl_init($url);
setCurl($ch, $header);
curl_setopt($ch, CURLOPT_HEADER, true); // 返回响应头
curl_setopt($ch, CURLOPT_NOBODY, true); // 只要响应头
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); // 获得响应头大小
$result = substr($response, 0, $header_size); // 根据头大小获取头信息
curl_close($ch);
return $result;
}
function getSubstr(string $str, string $leftStr, string $rightStr) {
$left = strpos($str, $leftStr); // echo '左边:'.$left;
$right = strpos($str, $rightStr, $left); // echo '
右边:'.$right;
if ($left < 0 or $right < $left) return '';
$left += strlen($leftStr);
return substr($str, $left, $right - $left);
}
function formatSize(float $size, int $times = 0) { // 格式化size显示 PHP版本过老会报错
if ($size > 1024) {
$size /= 1024;
return formatSize($size, $times + 1); // 递归处理
} else {
switch ($times) {
case '0':
$unit = ($size == 1) ? 'Byte' : 'Bytes'; break;
case '1':
$unit = 'KB'; break;
case '2':
$unit = 'MB'; break;
case '3':
$unit = 'GB'; break;
case '4':
$unit = 'TB'; break;
case '5':
$unit = 'PB'; break;
case '6':
$unit = 'EB'; break;
case '7':
$unit = 'ZB'; break;
default:
$unit = '单位未知';
}
return sprintf('%.3f', $size) . $unit;
}
}
function CheckPassword() { // 校验密码
if (IsCheckPassword) {
if (!isset($_POST["Password"])) {
if (isset($_SESSION["Password"])) {
if ($_SESSION["Password"] === Password) {
echo (isset($_POST["dir"]) || isset($_SESSION["ShowAlert"])) ? ''
: '';
$_SESSION['ShowAlert'] = true; return;
}
}
} else {
if ($_POST["Password"] === Password) {
$_SESSION['Password'] = $_POST["Password"];
echo (isset($_POST["dir"]) || isset($_SESSION["ShowAlert"])) ? ''
: '';
$_SESSION['ShowAlert'] = true; return;
}
}
die('
错误
密码错误!