@@ -43,13 +43,16 @@ class UserId extends VisitDimension
4343 * @return mixed|false
4444 */
4545 public function onNewVisit (Request $ request , Visitor $ visitor , $ action )
46- {
47- $ username = $ visitor ->getVisitorColumn ('user_id ' );
48- $ salt = Config::getInstance ()->General ['salt ' ];
49- $ usernamehash = substr ( sha1 ( $ salt .$ username ), 0 , 16 );
50- $ visitor ->setVisitorColumn ('user_id ' , $ usernamehash );
51-
52- return $ usernamehash ;
46+ {
47+ $ uid = $ visitor ->getVisitorColumn ('user_id ' );
48+ if (!empty ($ uid ))
49+ {
50+ $ salt = Config::getInstance ()->General ['salt ' ];
51+ $ hash = substr (sha1 ($ salt .$ uid ), 0 , 16 );
52+ $ visitor ->setVisitorColumn ('user_id ' , $ hash );
53+ return $ hash ;
54+ }
55+ return $ uid ;
5356 }
5457
5558 /**
@@ -61,11 +64,14 @@ public function onNewVisit(Request $request, Visitor $visitor, $action)
6164 */
6265 public function onExistingVisit (Request $ request , Visitor $ visitor , $ action )
6366 {
64- $ username = $ visitor ->getVisitorColumn ('user_id ' );
65- $ salt = Config::getInstance ()->General ['salt ' ];
66- $ usernamehash = substr ( sha1 ( $ salt .$ username ), 0 , 16 );
67- $ visitor ->setVisitorColumn ('user_id ' , $ usernamehash );
68-
69- return $ usernamehash ;
67+ $ uid = $ visitor ->getVisitorColumn ('user_id ' );
68+ if (!empty ($ uid ))
69+ {
70+ $ salt = Config::getInstance ()->General ['salt ' ];
71+ $ hash = substr (sha1 ($ salt .$ uid ), 0 , 16 );
72+ $ visitor ->setVisitorColumn ('user_id ' , $ hash );
73+ return $ hash ;
74+ }
75+ return $ uid ;
7076 }
71- }
77+ }
0 commit comments