Jump to content

How to find out which link was clicked on previous page


AdRock

Recommended Posts

I have a page which displays news articles.

I want to use the same page to display current news articles and archived news articles and display them depending on which link was clicked previously.

I am thinking i owuld have to use an if statement to take the right branch and to create the correct SQL query but i don't know how I would find out which link was clicked.

say I have a link called 'current news' and a link called 'archived news' how do i find ut which one was clicked so i can put it into the if statement?
I dont know if I understand you correctly But what I would do for my project is create a log table in your database that stores the name of the page loaded along with timestamp\ipaddress\page_name and other useful data. Once you have this data you can write functions like

user_last_page_viewed()
last_page_viewed()

these functions should return a page_id or page_name. and you should be able to use this data the way you want if i have understood you correctly

EDIT::

I said what i was most familiar with but you can easily do the same with sessions. At the bottom of your page store the page_name or page_id inside

$_SESSION['last_page_clicked'] = 'current_page_name';
Just a heads up: $_SERVER['HTTP_REFERER']; doesn't always work.  This information is sent by the client so it can be mutated or omitted all together.  If you're using this for statistical analysis and can tolerate 0 - 10% margin of error HTTP_REFERER will work.  If you need to be sure where the user came from for security reasons I'd go another route.

Best,

Patrick

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.