Jump to content

Last page visited in PHP


npsari

Recommended Posts

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

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>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.