Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9260475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:54:06+00:00 2026-06-18T12:54:06+00:00

I am making a session system for my website using PHP and MySQL. The

  • 0

I am making a session system for my website using PHP and MySQL. The idea is that a user session will last for around 5 minutes if they are inactive, and a CronJob runs every now and then and checks to see if sessions are expired, and if they are, removes the session.

The issue:

Every time someone loads their page it has to check the database to see if their session is still valid. I am wondering if in that CronJob task, I could make it find that users PHP Session and change a variable like $_SESSION['isValidSession'] and set it to false.

So once they load the page it just checks if that variable if the session is valid.

Sorry for the wall of text!

TL;DR: I want to modify session variables of different specified sessions.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:54:07+00:00Added an answer on June 18, 2026 at 12:54 pm

    Every time someone loads their page it has to check the database to
    see if their session is still valid. I am wondering if in that CronJob
    task, I could make it find that users PHP Session and change a
    variable like $_SESSION[‘isValidSession’] and set it to false.

    You have to do this regardless. When the users load their page, the system must verify whether the session exists in the database (I assume that you’re using a DB).

    If you run the cron job every minute, and expire all sessions older than five (which seems rather excessive? I often stay inactive on a site for five, ten, even fifteen minutes if I am reading a long page), this will automatically “mark invalid” (actually remove) the sessions.

    Normally you would keep a TIMESTAMP column with the time of last update of that row (meaning that session), and the cron job would DELETE all rows with timestamp older than five minutes ago. When reloading the page, the system would no longer find the relevant session row, and deduce (correctly) that the session has expired.

    However, what you want (reading a session knowing its SessionID) can be accomplished by reading in the session by the cron job (you can code the job in PHP) either loading as extant session given its ID, or by reading the DB column holding the serialized data with a SELECT SessionData FROM SessionTable WHERE id = 'SessionId'; and de-serializing it. Then you modify the inflated object, re-serialize it and store it back in the database with SQL UPDATE. Hey presto!, session has now been modified.

    But be aware that this will likely cause concurrency problems with active clients, and cannot be done in SQL in one fell swoop – you can’t execute UPDATE Sessions SET isInactive = 1 WHERE expiry... directly. Normally you need to read the rows of interest one by one, unserialize them and store them back, processing them with PHP code.

    You can do it indirectly with two different workarounds.

    One, you change your session code to use unserialized data. This will impact maintainability and performance (you can’t “just add” something to a session: you have to create a column for it).

    Two: you take advantage of the fact that in serialized form, “0” and “1” have the same length. That is, the serialized session containing isValidSession (name of 14 characters) will contain the text

     ...{s:14:"isValidSession";b:1;}...
    

    and you can change that piece of string with {s:14:"isValidSession";b:0;}, thus making isValidSession become False. This is not particularly good practice – you’re messing with the system’s internals. Of course, I don’t think anybody expects PHP’s serialized data syntax to change anytime soon (…or do they?).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a simple login form that saves to a database using MYSQL.
Why does changing/making errors in one's codebase sometimes destroy a session in Codeigniter/PHP? I
I am making an installer which will be 100% depending on system variable such
I am making quite a large online points/purchasing system in PHP and just have
How to create a custom login system with google-app-engine's User class? I'm making my
My website has a very granular permissions system for every client, making it fairly
I understand that the idea is to create basic HTTP Requests using GET or
I'm making a system with CakePHP that needs to be decently secure, because we're
I am making a registration/login system with php. I think I have all the
I'm making the following call in jQuery, using jsonp as my data format, that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.