My plugin requires me to save query data for some time. The data isn't big as such; just a couple of search parameters entered by the user so that I can use them across pagination.
I've figured out following ways to do this:
Setting up
session_start()
either in wp_config OR hooking it up to 'init' and then storing my data in$_SESSION
. Then destroying the session when user logs outUsing either
set_transient
orwp_cache_set
; which will store the data in the database; but with expiration time. Of course, I can have my code delete the transient to avoid bloat in the database.
Question: Are the transients shared by all the users visiting a site? So let's say user1 sets transient data; will it be available to user2?
- Use Cookies. This perhaps is the same as using
$_SESSION
; but I'm wondering if there'd be any security issues with this.
Which approach do you suggest? If there's any other more efficient approach - I'd like to know about it as well.
Thank you in advance!
My plugin requires me to save query data for some time. The data isn't big as such; just a couple of search parameters entered by the user so that I can use them across pagination.
I've figured out following ways to do this:
Setting up
session_start()
either in wp_config OR hooking it up to 'init' and then storing my data in$_SESSION
. Then destroying the session when user logs outUsing either
set_transient
orwp_cache_set
; which will store the data in the database; but with expiration time. Of course, I can have my code delete the transient to avoid bloat in the database.
Question: Are the transients shared by all the users visiting a site? So let's say user1 sets transient data; will it be available to user2?
- Use Cookies. This perhaps is the same as using
$_SESSION
; but I'm wondering if there'd be any security issues with this.
Which approach do you suggest? If there's any other more efficient approach - I'd like to know about it as well.
Thank you in advance!
Share Improve this question edited Jul 30, 2019 at 7:19 T.Todua 5,8809 gold badges52 silver badges81 bronze badges asked Dec 30, 2016 at 6:02 TheBigKTheBigK 5691 gold badge7 silver badges15 bronze badges 4 |1 Answer
Reset to default 4set_transient() using wp_cache_set() and mysql database. WP Cache API using $GLOBAL(global session for application).
Cookies and Session saves data only for one current user(cookies in browser, sessions on backend).
I think better using set_transient(), it has nice hooks and save all data global, even on site disabled cache.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745285384a4620526.html
Everyone seems to misunderstand how transient expiration works, so the long and short of it is: transient expiration times are a maximum time. There is no minimum age. Transients might disappear one second after you set them, or 24 hours, but they will never be around after the expiration time.
– nmr Commented Jul 30, 2019 at 7:29