php - Storing User Navigation History in a Cookie/Session -
i'm playing php , looking achieve following (i know possible third party plug-ins, want build on own practice):
- store history of urls user visits within (joomla driven) site in cookie.
- send array of values (other user information including url history) source (file or database) when user logs out. have not tackled item 2 yet, answer or pointer appreciated.
the php code i've created far:
$user = jfactory::getuser(); $helper = juserhelper::getusergroups($user->id); if(!isset($_cookie['pagehistory'])){ setcookie('pagehistory',$_server['request_uri'].'|'); } else { $_cookie['pagehistory'] .= $_server['request_uri'].'|'; } // debug: destroy cookie //setcookie ("pagehistory", "", time() - 3600); $group = ""; foreach ($helper $value) { $group .= $value."|"; } $userinfo = array( 'id' => $user->id, 'username' => $user->username, 'realname' => $user->name, 'group' => $group, 'url' => $_server['request_uri'], 'history' => $_cookie['pagehistory'], );
the issue i'm having 'pagehistory' cookie. when test using console, seem first url , ever-overriding second, no more.
example:
nav url 1: '/' //(root)
nav url 2: '/news'
nav url 3: '/tutorials'
results of cookie code:
round 1 : '/'
round 2 : '/|/news' // '|' being delimiter
round 3 : '/|/tutorials' // instead of '/|/news|/tutorials'
what doing wrong?
cookies created setcookie
function. change else following , see if fixes it:
else { $tmp = $_cookie['pagehistory'] . $_server['request_uri'] . '|'; setcookie('pagehistory', $tmp); }
Comments
Post a Comment