Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Is there any way to check for user login and send him to login?

When a user logs out the current user session is destroyed and no new pages can be loaded for which a user must be logged in. However, when you hit the ‘back’ button on your browser, it typically retrieves the page from the local cache. There is no contact with the server to see if the current session is still valid.

So, what you need to do is detect whether the backspace button has been hit and in that case check the validity of the session. This means there must be a piece of javacript included in the page, because this action needs to take place at the user side. I’m not a security expert, but the common way to detect the backspace goes like this:

window.onhashchange = function() {
 .. your action ..
 }

There are some snags to this method. Now, your action must be to call back to the server. That question has been answered before here on WPSE.

Related Posts:

  1. Can someone explain what wp_session_tokens are, and what are they used for?
  2. Log in from one wordpress website to another wordpress website
  3. Verify if user is wordpress logged in from another app since wordpress 4.0
  4. Logout users upon login, based on caps/role?
  5. Need edit profile link in the menu for logged in users
  6. How to store username and password to API in wordpress option DB?
  7. In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
  8. How to properly validate data from $_GET or $_REQUEST using WordPress functions?
  9. Nonces can be reused multiple times? Bug / Security issue?
  10. WordPress and PHP Sessions – Security and Performance
  11. What is the difference between esc_html and wp_filter_nohtml_kses?
  12. Init action hook running late after PayPal’s return url?
  13. How to check WordPress website username and password is correct
  14. Masking logout URL
  15. Nonce in settings API with tabbed navigation
  16. Problems after wp_set_password() containing an apostrophe
  17. Escaping built-in WP function return strings
  18. What is the difference between strip_tags and wp_filter_nohtml_kses?
  19. WP Cron doesn’t save or in post body
  20. Two-step login process – Is it possible?
  21. How do I approach removing menu items on the fly based on settings in my plugin?
  22. WordPress restrict plugin file direct access
  23. Plugin development: is adding empty index.php files necessary?
  24. Confusion on WP Nonce usage in my Plugin
  25. Coding a plugin on WordPress; when should I sanitize? [duplicate]
  26. Correct way check nonce (security) using old Options API
  27. Why do I need to check if wp_nonce_field() exists before using it
  28. WordPress security issue to output data from user input from theme option form
  29. Proper way to pass credentials in a custom login form to avoid “headers already sent”
  30. External Authentication, session_tokens not destroyed on logout
  31. How to customize login process
  32. Secure Pages Best Practice
  33. wp_insert_user() function password never match
  34. Does wp_login only trigger before an user signs in into the admin panel?
  35. Securing/Escaping Output of file content – reading via fread() in PHP
  36. Is it possible to make sure that only my plugins output is shown to the enduser?
  37. Password field is empty when using wp_signon();
  38. best way to make a WordPresss multisite that is secure but at the same time supporting my plugin development efforts
  39. Video Security just like facebook [closed]
  40. Plugin Development for registered users
  41. Is disabling test_form in wp_handle_upload a security concern?
  42. How to connect my wordpress plugin to a remote database securely?
  43. wp_nonce_field displaying twice
  44. Enqueue script globally
  45. WP Multisite login not working on one subsite. Possibly cookies/ history issue?
  46. Is it necessary to do validation again when retrieving data from database?
  47. Checking a WordPress for OWASP top 10 vulnerabilities [closed]
  48. How do I have now a duplicated user entry if this is not allowed (and I cannot replicate it)?
  49. add_submenu_page hooked function must explicitly check user capabilities – why?
  50. Are there any security risks when submitting data-attribute data through AJAX?
  51. Why would you use esc_attr() on internal functions?
  52. Logout after clicking URL link results in “headers already sent” error
  53. How do I validate extra pin field on my WordPress login form page?
  54. Is it possible to use WP-CLI in a plugin (or theme)?
  55. Secruity Questions on a timer
  56. How to redirect home page to another page after login for all user?
  57. Using HTML links within translatable string
  58. How can I save a password securely as a settings field
  59. How to share user data across multiple WordPress websites?
  60. Using password protection to load different page elements?
  61. HTML Elements in my WP Plugin being generated in JS. Security and Translated Text Question about this method being used
  62. Allowing duplicating users with same user_login and user_email
  63. How to Login a User inside a Plugin and Redirect to page?
  64. Using custom IDP with WP
  65. Hiding the WordPress login and password fields from login page
  66. How to store sensitive user data (passwords)
  67. How do I make secure API calls from my WordPress plugin?
  68. esc_attr() on hard coded string
  69. how to add security questions on wp-registration page and validate it
  70. redirect_to how to make it simply work with get parameter or similar?
  71. Experts opinions needed: How (in)secure is this approach?
  72. What is more secure checking capabilities of user or checking role of user in WordPress plugin development
  73. Multiple Users Logged In Causing Incorrect Account Returned
  74. Data Validation, dynamically generated fields (select for example)
  75. Get user logged in status from within a plugin. $current_user not defined
  76. Create a Custom Login System in WordPress [closed]
  77. how can I insert a link on login page
  78. user can login from single account detail from multiple locations(computer) at the same time [closed]
  79. esc_url, esc_url_raw or sanitize_url?
  80. how to works woocommerce cart hash
  81. Workflow for new importer plugin – your advices?
  82. Change author permalink to external URL
  83. Writing editor content to a file
  84. Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
  85. Plugin Form Submitting to admin-ajax.php instead of admin-post.php
  86. Unable to access custom plugin backend
  87. Plugin Development – Multilangual – Different pages
  88. Simple plugin don’t display content
  89. Screenshots on plugin page taken old [closed]
  90. How to translate wordpress backend to another language
  91. Plugin Development – Get Admin Url (Including cases where wp-admin is not used)
  92. How to create two custom post types when plugin is activated?
  93. How to hide page links from theme menu
  94. Get post thumbnail in WP_Query
  95. Brainstorm – Slow Query from Plugin Need to Speed It Up
  96. Unexpected T_FUNCTION
  97. How to avoid conflicts with db.php / $wpdb and other plugins that decide to use them?
  98. Plugin settings are saving but the fields
  99. Plugin can’t be activated [closed]
  100. WordPress Login/Logout Single Menu Only
Categories plugin-development Tags login, logout, plugin-development, security
Get all meta keys assigned to a post type
Thumbnails are bigger in size than the original image

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress