Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By 12stringblues on
Hello,
I'd like to know if anyone has a php snippet that would show the last x number of nodes a particular user has viewed. I saw this on a site recently and really liked it, but couldn't tell what CMS it was.
I envision a block in the upper right corner that would show the last 3 pages that the user has viewed to allow for easier navigation.
Any ideas would be appreciated.
Comments
Try what is here.
it needs customised though:
http://drupal.org/node/45286
I don't think that is what I
I don't think that is what I really need, unless I'm not understanding the code. I understand how to pull recently changed content, the most recent nodes, etc. What I need is the recently viewed pages tied to the current user that is logged in (or even a guest for that matter). I could get the last viewed pages with some javascript code to use their browsers history entries, but I would like something more internal to drupal. Anyone else have any ideas?
Use statistics and blocks
The following script implements this in a simple way (on Drupal 5.x). You can put it in a block:
This workd great. How to limit to specific node type?
This block works great. I want to use to display only "products" visited. It is returning "every page" visited. Any suggestions would be a great help.
Thanks in advance,
Tim "t4him" Moyers
The solution above is
The solution above is limited and relies on the statistics module which doesn't save the node type (since it logs all accesses not just node accesses). You could wrestle with the `accesslog` table to try to guess which entry was a node (e.g. it has path = node/*) and then load the nid to check its type. But that's a long and inefficient solution. Better, you could implement hook_nodeapi() and catch all 'view' operations on your node type of interest, saving them in your own table with the uid that visited. HTH.
session?
kratib
Why not just put them in session instead of database?
HillsWeb.com
Hills Web
Good idea! Even simpler.
Good idea! Even simpler.
I expanded on this to fix a
I expanded on this to fix a couple problems. 1) Your code would only work for users logged in. Worse, if they aren't logged in, then they see what other "Anonymous" users are doing in their history... which isn't the intended effect. 2) As someone else mentioned this wouldn't limit the results to any particular set of pages. I did this by simply checking the url against a string, which for me works great because I use pathauto, so it's pretty predictable, and still lightweight.
Does this work with 6.x? I
Does this work with 6.x? I tried it on mine and I'm not seeming to get it to work...
Thanks!
You can also do this pretty
You can also do this pretty easily in Views by making an "access log" view and using filters.
Hi, can you elaborate a
Hi, can you elaborate a little more on the views and access log?
thanks
DS
DS, If you're using Views,
DS,
If you're using Views, you can create a view which shows your user access log. Here's mine (keep in mind, this shows only two types of content ... your needs may vary)
thanks for that but would
thanks for that but would this code be an export for drupal 4? I have 5
This is code for Drupal 6
This is code for Drupal 6 and the latest build of Views.
thanks, I'll keep that for
thanks, I'll keep that for when i upgrade. Is this a new feature (draw data from access log) in 6 only?
I don't think that is what I
I do not think that is what I really need, unless I'm not understanding the code. I understand how to pull recently changed content, the most recent nodes, etc. What I need is the recently viewed pages tied to the current user that is logged in (or even a guest for that matter)? I could get the last viewed pages with some javascript code to use their browsers history entries, but I would like something more internal to drupal. Anyone else have any ideas?
Double entrees
This seems to work (make sure the statistics module is on). But despite of the distinct function that is on. We get a lot of double entrees. Any way to eliminate this so each page is being displayed only once?
Seems to be the way views generates its query
GoalGorilla,
This is the query that I got in my views setup screen:
As you can see, views is interjecting additional columns in the query. I don't know the way around this per se using the Views UI. However, I have expanded on code previously written in this thread and created a fully functional block to take care of this.
In addition to the code written previously, this block has a configuration form:
Here is the code:
Noah Lively
Founder and CEO,
Kore Innovations
http://www.koreinnovations.io
Good stuff!
Hi noahlively,
This is what we need! How do I implement this block code?
Many thanks in advance!
Hi all, This is exactly what
Hi all,
This is exactly what I am looking for. I put this snippet in a block with php enable but I couldn't get any result.
I guess I didn't set the path properly. Could anyone explain how to do it?
Or I should put this snippet somewhere else instead of in a block?
Excuse me, I am quite new to Drupal. But I really need this feature on the site I am working on.
Thanks
_
The code above is module code, not block code. Either create a little custom module, or use the custom block snippet version.
Thanks Worldfallz, I tried
Thanks Worldfallz,
I tried that as well, but I don't know what to do with this:
i tried this, but it didn't work
_
The line that creates the filter is:
$criteria[] = sprintf(" url LIKE '%s' ", $url_filter);
So, using your string, you created:
url LIKE WHERE path LIKE node/%
I'm no sql guru, but that doesn't look valid to me ;-)
Thanks for pointing that out,
Thanks for pointing that out, WorldFallz. I am a sql newbie and I am still learning, but I really like the idea of having the recently viewed item on the site I am building. What if I want to show "content/event/%" and "content/meeting/%" in the recently viewed item block? I tried copy your code into the block and change '%s' to 'node/%', it didn't work and gave me an error message.
arse error: syntax error, unexpected T_GLOBAL. could you please explain this a little bit.
_
This is only a guess, but try:
$url_filter = 'node';
i still couldn't get it to
i still couldn't get it to work. But that's alright. Maybe I could when I learn a bit more sql. Thanks!
_
Couple more guesses:
$url_filter = 'node%';
$url_filter = '%node%';
did you have any luck with
did you have any luck with this? it`s a really nice feature.
--------------------------
http://www.mortenn.no
_
Awesome snippet! Posted to the block snippets section altered to be a self contained custom block: http://drupal.org/node/533358 so it doesn't require a module.
no result
After changing 'accesslog' into the right table with prefix (XXX_accesslog) we got the Block working!
_
That would be true for all snippets if you're using prefixed tables.
Referer URI?
On line 64 of statics.module data is written to the accesslog.
Why do we use referer_uri() for the URL instead of request_uri? This makes no sense for the recent visited pages....
Hello, First you have to
Hello,
First you have to enable a statistics module at admin/builld/modules.
You can use the views to make a block and choose the sort criteria,Node statistics: Most recent view and choose the filter and filters according to your need.
Thanks,
Saurabh.
Saurabh, I've been searching
Saurabh,
I've been searching around for a statistics module and I cannot decide which one is right for this. Could you please recommend a statistics module that I should use with the described view?
Thank you in advance,
Mike
SQL Injection vulnerability
You should use db_query placeholders, not attempt to emulate them with sprintf. $url_filter will not be properly escaped in the example.
subscribing
subscribing
Would be a nice contribution
Would be a nice contribution I think --> http://drupal.org/node/691996#comment-2507098
--------------------------
http://www.mortenn.no
Recently read module
You can try my module for displaying recently read nodes (with configurable node types). It's currently in a sandbox:
http://drupal.org/project/recently_read
Easiest way to show LATEST VIEWED NODES list ?
Easiest way to show LATEST VIEWED NODES list ?
Hi,
Can you tell me what is the easiest way to show the latest viewed nodes list now ?
I want to use it for to show customers latest viewed products on Ubercart shop.
Thanks a lot.
@make-online-shop: The
@make-online-shop:
The Recently Read module posted above sounds promising and I'd recommend you try that first. I was able to get a Recently Viewed block on my Ubercart site using Flag, Rules, and View modules as per Jan Tomka's walk-through discussed here: http://jan.tomka.name/blog/list-recently-viewed-nodes-drupal
Here is a sample of Jan's list of recently viewed nodes operating on my Ubercart site: http://www.marlincrawler.com Click around on a few products and you'll see a block beneath my upsell block (Related products) that shows Recently Viewed Products.
Jan's method involves three modules and a bit of setup work, so I'd try the Recently Read module first to see if that will work for you.
Good luck,
BigMike
Holy smokes, earlier today I
Holy smokes, earlier today I updated my Views for the new critical security issue, and just now noticed that my Recently Viewed Products is no longer working!! >_< CRAP! Now I gotta find out what changed with Views!! :-(
Recently viewed products works but not for anonymous when CACHE
Recently viewed products works with Ubercart but not for anonymous when CACHE enabled
Hi,
Thank you, the recently viewed module works with Ubercart for logged users but no pictures of the products are shown and it seems not to work with Anonymous users when CACHE is enabled.
Any other idea ?
Thanks.
Fixed in Views 6.x v2.16
I just updated to Views 6.x-2.16 and my "Recently Viewed Products" view was automagically restored to its former glory! WHEW!
Sorry offtopic
Sorry offtopic, but your small cart in the menu is so cute :-) How did you do it and does it work for unlogged users because it is an Ajax cart ? Would like to have the same !
And I didn't see your recently viewed products on the shop ?
make-online-shop, I got the
make-online-shop,
I got the problem fixed. It was an issue with Views 6.x-2.14. Please check my site again and you will see a Recently Viewed Products block appear at the bottom of any product page once you have viewed more than 1 product.
Thanks!
Mike