/**
* 获取当前http协议
* @date 2018-04-18
*/
function getProtocol()
{
if (!input('?server.REQUEST_SCHEME')) {
$protocol = input('server.SERVER_PORT') == 443 ? "https" : "http";
} else {
$protocol = input('server.REQUEST_SCHEME');
}
return $protocol;
}
/**
* 获取当前全部url链接
* @date 2018-11-27
*/
function getUrl()
{
$protocol = getProtocol();
return $protocol . '://' . input('server.HTTP_HOST') . input('server.REQUEST_URI');
}
/**
* 获取当前的网址加目录信息
* @date 2018-11-27
*/
function getDomain()
{
$request = \think\Request::instance();
$domin = $request->domain();
return $domin;
}
/**
* 获取当前或者服务器端的IP 2018-04-19
* @param int $type 获取服务器IP类型 1为本地服务器 2为代码服务器
*/
function getClientIp($type = 1)
{
if ($type == 1) {
return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
} else if ($type == 2) {
return isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '0.0.0.0';
}
}
/**
* 检测手机号 2017-10-15
*/
function isMobilephone($mobilehone = '')
{
if (preg_match("/1[3456789]{1}\d{9}$/", $mobilehone)) {
return true;
} else {
return false;
}
}
/**
* 检验是否是座机号
* @param string $seat_number
* @return bool
*/
function isSeatNumber($seat_number = '')
{
$isTel = "/^([0-9]{3,4}-)?[0-9]{7,8}$/";
if (!preg_match($isTel, $seat_number)) {
return false;
} else {
return true;
}
}
/**
* 检验是否是座机号或是手机号
* @param string $phone
* @return bool
*/
function isPhone($phone = '')
{
$isMob = "/^1[3-9]{1}[0-9]{9}$/";
$isTel = "/^([0-9]{3,4}-)?[0-9]{7,8}$/";
if (!preg_match($isMob, $phone) && !preg_match($isTel, $phone)) {
return false;
} else {
return true;
}
}
/**
* 检测身份证号 2018-03-21
*/
function isCreditNo($vStr)
{
$vCity = array(
'11', '12', '13', '14', '15', '21', '22',
'23', '31', '32', '33', '34', '35', '36',
'37', '41', '42', '43', '44', '45', '46',
'50', '51', '52', '53', '54', '61', '62',
'63', '64', '65', '71', '81', '82', '91'
);
if (!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/', $vStr))
return false;
if (!in_array(substr($vStr, 0, 2), $vCity))
return false;
$vStr = preg_replace('/[xX]$/i', 'a', $vStr);
$vLength = strlen($vStr);
if ($vLength == 18) {
$vBirthday = substr($vStr, 6, 4) . '-' . substr($vStr, 10, 2) . '-' . substr($vStr, 12, 2);
} else {
$vBirthday = '19' . substr($vStr, 6, 2) . '-' . substr($vStr, 8, 2) . '-' . substr($vStr, 10, 2);
}
if (date('Y-m-d', strtotime($vBirthday)) != $vBirthday)
return false;
if ($vLength == 18) {
$vSum = 0;
for ($i = 17; $i >= 0; $i--) {
$vSubStr = substr($vStr, 17 - $i, 1);
$vSum += (pow(2, $i) % 11) * (($vSubStr == 'a') ? 10 : intval($vSubStr, 11));
}
if ($vSum % 11 != 1)
return false;
}
return true;
}
/*
* 检查邮箱格式是否正确 2018-09-19
*/
function isEmail($email = '')
{
$mode = '/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/';
if (preg_match($mode, $email)) {
return true;
} else {
return false;
}
}
/**
* 根据经纬度计算距离 2017-10-15
* @param $lat经度 $lng维度
*/
function getdistance($lat1, $lng1, $lat2, $lng2)
{
$EARTH_RADIUS = 6378.137;
$radLat1 = rad($lat1);
$radLat2 = rad($lat2);
$a = $radLat1 - $radLat2;
$b = rad($lng1) - rad($lng2);
$s = 2 * asin(sqrt(pow(sin($a / 2), 2) +
cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2)));
$s = $s * $EARTH_RADIUS;
$s = round($s, 3); //千米为单位,3位小数
return $s;
}