3
This commit is contained in:
parent
b3e8369b25
commit
4737960d22
@ -12,17 +12,18 @@ final class VisitorCount
|
|||||||
public static function From()
|
public static function From()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// var_dump(self::normalizeUrl($_SERVER['HTTP_REFERER']));
|
||||||
// 如果以被设置,什么都不做
|
// 如果以被设置,什么都不做
|
||||||
// 如果未被设置,入库并保存cookie,注册用
|
// 如果未被设置,入库并保存cookie,注册用
|
||||||
if (!isset($_COOKIE['VisitorFrom'])) {
|
if (!isset($_COOKIE['VisitorFrom'])) {
|
||||||
|
|
||||||
if (isset($_SERVER['HTTP_REFERER'])) {
|
if (isset($_SERVER['HTTP_REFERER'])) {
|
||||||
|
|
||||||
$sFrom = $_SERVER['HTTP_REFERER'];
|
$sFrom = self::normalizeUrl($_SERVER['HTTP_REFERER']);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$sFrom = "直接";
|
$sFrom = $_ENV['short_url'];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,4 +37,18 @@ final class VisitorCount
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function normalizeUrl($url) {
|
||||||
|
|
||||||
|
$parsedUrl = parse_url($url);
|
||||||
|
|
||||||
|
$host = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
|
||||||
|
|
||||||
|
if (strpos($host, 'www.') === 0) {
|
||||||
|
$host = substr($host, 4); // 去掉 'www.'
|
||||||
|
}
|
||||||
|
|
||||||
|
return $host;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user