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 9177251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:16:52+00:00 2026-06-17T17:16:52+00:00

I have like an if/else statement which checks if the user is still logged

  • 0

I have like an if/else statement which checks if the user is still logged in, else display message saying they need to log in. This is included just in case the session has expired. Now what I also have in the else statement is a mysqli code where it will perform a quesry to delete any rows in Session_Complete and Session table where the TeacherId belongs to the user which was logged in and where the Session_Complete is 0. Now this doesn’t work and this is really obvious because obviously the session has been expired meaning that the teacher is not logged in as their details have been destroyed when the session has been expired and thus it cannot recognize which teacher is logged so the query can’t delete an rows.

So my question is that if somebody was trying to tackle the same problem where the qwnt a query to be performed if the user has been logged out due to a session expire, then how would you be able to do it so that just before the session has expired it would somehpw get the TeacherId, $userid of the teacher that was logged in, so then it can be used in the query, while displaying the message that the user needs to login?

Below is the current if/else statement:

if ((isset($username)) && (isset($userid))){ //checks the logged in teacher's username and userid

//whole page code here

}else{ 

echo "Please Login to Access this Page | <a href='./teacherlogin.php'>Login</a>";

$incomplete = 0;            

    $deletesession = " DELETE session, session_complete FROM Session AS session 
    LEFT JOIN Session_Complete AS session_complete
    ON session_complete.SessionId = session.SessionId
    WHERE (session.TeacherId = ? AND Complete = ?) "; 

                if (!$delete = $mysqli->prepare($deletesession)) {
      // Handle errors with prepare operation here
    }

    //Dont pass data directly to bind_param store it in a variable
$delete->bind_param("ii",$userid, $incomplete);

 $delete->execute();

        if ($delete->errno) {
          // Handle query error here
        }

        $delete->close();


}

?>
  • 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-17T17:16:54+00:00Added an answer on June 17, 2026 at 5:16 pm

    The only thing you can do is keep track of either the expected expiry time of the session, based on how long you’ve set the session cookie to last, or the last activity time of the user, and store that in the database record.

    You’ll have to set up a cron job to sweep up the session table every so often, and check for sessions that are past their expiry time. If you can’t use a cron job for whatever reason, you can set your regular code to randomly call the session garbage collector every so many views (depending on your typical number of visitors).

    You could also try something like checking IP addresses and User-Agent headers, and try correlate those with a session, but that’s pretty error prone and I wouldn’t recommend it.

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

Sidebar

Related Questions

Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Good day, I have like 15 images I need to be buttons. I have
Have dict like: mydict= {'a':[],'b':[],'c':[],'d':[]} list like: log = [['a',917],['b', 312],['c',303],['d',212],['a',215],['b',212].['c',213],['d',202]] How do i
I have a PHP file which creates a unique directory for each user when
I have a form which allows my user to edit the information as required.
I have a project which requires using user input to include files into a
I'm trying to write a case statement in mysql which checks if a person
I have many checks to determine what role a user is in and then
I have the below code which checks to see if folder exists on the
So I have a script which checks the login details.. I have that working,

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.