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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:56:37+00:00 2026-05-25T19:56:37+00:00

What I am trying to do is give user access to an application once

  • 0

What I am trying to do is give user access to an application once every 24 hours.
Once they log out they have to wait another 24 hours before they can log in to.
But what I have notices is if it has been longer then an hour it works.
But if it has been less then an hour it still gives them access which I don’t want to happen.
What can I do to fix this code?

$dsn = 'mysql:dbname=DBNAME;host=127.0.01';
$user = 'USER';
$password = 'PASSWORD';

try {
    $dbh = new PDO($dsn, $user, $password); }
catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}


function currentMysqlTime($dbh) {
    $sql = $dbh->prepare("SELECT CURRENT_TIMESTAMP()");
    $sql->execute();
    $x = $sql->fetchAll();
    return $x[0][0];
}

 function lastLoginTime($dbh, $id) {
    $sql = $dbh->prepare("SELECT * FROM userpoints WHERE uid = ? AND pid = 2 ORDER BY timestamp desc LIMIT 1");
    $sql->execute(array($id));
    $y = $sql->fetchAll();
    return $y[0][3];
}
 function mysqlTimeDiff($dbh, $x, $y) {
    $sql = $dbh->prepare("SELECT TIMEDIFF(?, ?)");
    $sql->execute(array($x, $y));
    $z = $sql->fetchAll();
    return $z[0][0];
}
    function daysSinceLastLogin($x) {
      $parts = explode(':',$x);
      return $parts[0];
}

$currentMysqlTime = currentMysqlTime($dbh);
$lastLoginTime = lastLoginTime($dbh, $id);

    $timeDiff = mysqlTimeDiff($dbh, $currentMysqlTime, $lastLoginTime);
    $daysSinceLastLogin = daysSinceLastLogin($timeDiff);

if($daysSinceLastLogin < 0) {
//NO ACCESS AS THE USER HAS ALREADY LOGGED IN

} else {
//GRANT ACCESS AS IT IS THERE FIRST TIME LOGGING IN TO THE APPLICATION
}

This is the output of the functions

Time of Registration 2011-09-16 07:10:04
Current Mysql Time 2011-09-17 05:41:22
Last Login Time 2011-09-14 05:00:07
Time Difference 72:41:15
Date Difference 3

  • 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-05-25T19:56:38+00:00Added an answer on May 25, 2026 at 7:56 pm

    With the code below will give you a boolean you can use to determine the authorization to log in.

    $timestamp = strtotime('-24 hours', currentMysqlTime($dbh)); 
    $allowedToLogin = (bool) $dbh->fetchOne('SELECT 1 FROM  * FROM userpoints WHERE uid = ? AND timestamp <= ?', array($uid, $timestamp)); // Assuming ZF syntax here
    

    If there is a match for a timestamp inferior to the reference, you’re good to go for a login by verifying the boolean $allowedToLogin.

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

Sidebar

Related Questions

What I'm trying to do is give my user 4 options (simple links). If
I am trying to use some Word 2007 automation where we give the user
OK I give up - after 5 solid hours trying to get a django
I'm trying to return a plain javascript if a user access to a given
I'm trying to retrieve the access level (admin/member/guest) for the currently logged in user
I'm trying to iron out the last few bugs in my application. With my
I'm new to rails and am trying to give TDD a try. I have
I am trying to implement a validation strategy in my application. I have an
I'm trying to store a user's post into an access database through a web
Is it possible to retrieve an user id before agreeing to give permissions to

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.