npsari Posted May 2, 2008 Share Posted May 2, 2008 I know how to display a link, which takes the visitor back 2 pages print"<a href=\"#\" onClick=\"history.go(-2)\">Go back</a>"; But i dont know how to display the URL of that old page I want instead of Go back to be the actual URL Like that: print"<a href=\"#\" onClick=\"history.go(-2)\">/groups/general_chat/</a>"; Can you help Link to comment https://forums.phpfreaks.com/topic/103847-last-page-visited-in-php/ Share on other sites More sharing options...
rhodesa Posted May 2, 2008 Share Posted May 2, 2008 You will have to use SESSIONS. Put this code into a file and include it at the top of every page: <?php session_start(); //Start session if(!is_array($_SESSION['history'])) $_SESSION['history'] = array(); //Initialize array_unshift($_SESSION['history'],$_SERVER['REQUEST_URI']); //Add current page to beginning array_splice($_SESSION['history'],10); //Cap the list at 10 items function getHistory ( $idx = 1 ) { return $_SESSION['history'][$idx]; } Then, on your page where you want the link: <?php include('history.php'); //This should be the first line of the page // //Your other code // print "<a href=\"javascript:history.go(-2)\">".getHistory(2)."</a>"; Link to comment https://forums.phpfreaks.com/topic/103847-last-page-visited-in-php/#findComment-531667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.