tags:

views:

42

answers:

1

Hi guys,

I'm sure many of you have visited amazon.com. When you do, amazon creates a list of browsed menu items at the very bottom of the home page.

I am currently doing a project that applies personalisation and customisation and wanted to implement something similar. My prototype is based on an institution, so I want to display a list of, say, the last 5 viewed programmes or courses on the home page. I am using PHP and so far i have thought of using $_SERVER["HTTP_REFERER"], but this returns only the last URL, which is not what I want. Does anyone have any suggestions to help me with this?

Thanks.

+1  A: 

What you could do is something like what follows:

  • setup an array in a session variable for the document history inside that site:
  • each time the user visits one of the pages you want recorded, append that URL to the session variable

    $_SESSION['history'][] = $_SERVER['REQUEST_URL'];
    
  • if you want to limit the array's length, use a function in which you check the length and optionally remove the oldest element as you append a new one (this is in principle a FIFO queue).

  • Create your list iterating on the session array built in the previous steps.

This assumes that you want to show the last programmes / courses that the user visited. If you want to show the last programmes visited by all visitors to the site, you'll have to do something similar to the above but using something to keep track of global state, like a database or a file.

Adriano Varoli Piazza
Hi Adriano, Well as i am a novice in php, this is what i am doing thus far; <?php session_start(); $url_array=array(); $_SESSION['history']=$url_array; ?> Is there a php function that could get the current url for you? when this is retrieve, i basically need to store it in the array and then append it to the session variable? i am asking because i am an expert in php. i appologise for the trouble.
pundit
Try reading http://www.php.net/manual/en/reserved.variables.server.php to see what you need.
Adriano Varoli Piazza
i am asking because i am an expert in php suppose to read - i am not an expert. kind regards
pundit
So the script above is basically going in the pages that i want to store?
pundit
ok i did basically what you told me to do and it works. its just to manipulate it accordingly.. Thanks
pundit