I recently created this code for my client, I use an array for cookies in this code, in fact this code receives recently viewed pages by the user using cookies, I hope this helps you ...!
function curPageURL() { // get url return 'http' . (( !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ) ? 's' : '') . '://' . $_SERVER['SERVER_NAME'] . ( $_SERVER['SERVER_PORT'] == 80 ? '' : $_SERVER['SERVER_PORT'] ) . $_SERVER['REQUEST_URI']; } $currentPage = curPageURL(); // call function $counter = $_COOKIE['_counter']; // set counter variable if(!$_COOKIE['_PAGES']){ // if _Pages cookie $default = 1; // set default value to 1 setcookie("_counter",$default,time()+7200); // set counter cookie setcookie("_PAGES[$default]",$currentPage, time()+3600); // set cookie } else{ // if ! _Pages cookie $default = $counter+1; // set default value to +1 setcookie("_counter",$default,time()+7200); // set counter cookie } if(@in_array($currentPage, @$_COOKIE['_PAGES'])){ // if same url found } else{ // if new url found setcookie("_PAGES[$default]",$currentPage, time()+3600); // set cookie } if($_COOKIE['_PAGES']){ foreach ($_COOKIE['_PAGES'] as $value){ echo "<a href='{$value}'>{$value}</a>"; } }
Shakeel Memon Dec 14 '15 at 20:10 2015-12-14 20:10
source share