AdRock Posted January 21, 2007 Share Posted January 21, 2007 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? Link to comment https://forums.phpfreaks.com/topic/35091-how-to-find-out-which-link-was-clicked-on-previous-page/ Share on other sites More sharing options...
Nameless12 Posted January 21, 2007 Share Posted January 21, 2007 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 likeuser_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 correctlyEDIT::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'; Link to comment https://forums.phpfreaks.com/topic/35091-how-to-find-out-which-link-was-clicked-on-previous-page/#findComment-165624 Share on other sites More sharing options...
chronister Posted January 21, 2007 Share Posted January 21, 2007 $_SERVER['HTTP_REFERER'];this will give you the name of the page a person came from. Works Great. Link to comment https://forums.phpfreaks.com/topic/35091-how-to-find-out-which-link-was-clicked-on-previous-page/#findComment-165684 Share on other sites More sharing options...
utexas_pjm Posted January 21, 2007 Share Posted January 21, 2007 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 Link to comment https://forums.phpfreaks.com/topic/35091-how-to-find-out-which-link-was-clicked-on-previous-page/#findComment-165723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.