You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
user_center/app/Libs/MyLib.php

73 lines
2.0 KiB

<?php
namespace App\Libs;
/**
* @title MyLib
* @description MyLib
* @package App\Service
* @author zcstatham
* @time 2021/1/25
*/
class MyLib
{
public static function scanFile($path) {
$result = array();
$files = scandir($path);
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
if (is_dir($path . '/' . $file)) {
self::scanFile($path . '/' . $file);
} else {
$result[] = substr(basename($file), 0, -4);
}
}
}
return $result;
}
public static function Parser($text) {
$doc = new Doc();
return $doc->parse($text);
}
public static function GetClientIP()
{
global $HTTP_SERVER_VARS;
if (isset($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])) {
$ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
} elseif ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"]) {
$ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
} elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"]) {
$ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
} elseif (getenv("HTTP_X_FORWARDED_FOR")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
} elseif (getenv("HTTP_CLIENT_IP")) {
$ip = getenv("HTTP_CLIENT_IP");
} elseif (getenv("REMOTE_ADDR")) {
$ip = getenv("REMOTE_ADDR");
} else {
$ip = "0.0.0.0";
}
return $ip ;
}
public static function GetServerIP()
{
$ip = '0.0.0.0';
if (isset($_SERVER)) {
if (isset($_SERVER['SERVER_ADDR'])) {
$ip = $_SERVER['SERVER_ADDR'];
} elseif (isset($_SERVER['LOCAL_ADDR'])) {
$ip = $_SERVER['LOCAL_ADDR'];
} elseif (isset($_SERVER['SERVER_NAME'])) {
return gethostbyname($_SERVER['SERVER_NAME']);
}
} else {
$ip = getenv('SERVER_ADDR');
}
return $ip;
}
}