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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:28:52+00:00 2026-06-07T00:28:52+00:00

I am programming a website that use jQuery’s asynchrony to call php scripts. To

  • 0

I am programming a website that use jQuery’s asynchrony to call php scripts. To avoid double script calling I would like to do two things:

  • disable the buttons that will trigger the script call, which I have successfully done
  • set a timer in the php script that is called that will check whether it was called by the same user less than one second ago, and if so, exits

First I thought this would be relatively easy, and came up with the following code:

if(!isset($_SESSION['time'])) $_SESSION['time']=time();
else if(time()-$_SESSION['time']<=1){
    //If less than one second ago, timer reset
    $_SESSION['time']=time();
    exit;
}

It works fine the first time, but then afterwards, when it should check again, of course a very old time has been saved in the session and is still in there, so the script can be called as often as the user wishes.

Do you have any ideas how to solve this? Thank you!

Charles

EDIT

My question could possibly be a duplicate of this – do you see any value in the second answer maybe?

SOLUTION FOUND

This is the solution:

if(!isset($_SESSION['time']) || ($_SESSION['time'] + 1 < time())){
    $_SESSION['time'] = time();
}else if(time()-$_SESSION['time']<=1){
    //Timer reset
    $_SESSION['time']=time();
    exit;
}
  • 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-07T00:28:54+00:00Added an answer on June 7, 2026 at 12:28 am

    The simplest fix would be to overwrite the time value if it is set but is older than X seconds:

    if(!isset($_SESSION['time']) || ($_SESSION['time'] + 30 < time())) {
        $_SESSION['time'] = time();
    }
    

    change the 30 value to the timeout you want.

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

Sidebar

Related Questions

I am programming a script that will grab some data from my website using
Is there any website which provides core java based programming challenges that tests programming
I am programming a django based website. I actually use a small computer under
I'm programming a website using Foundation theme for wordpress that is setup for responsive
I am willing to build a wiki-based website that would have some other features,
We are programming a website which use UPS as shipping method. Administrator of the
I am a newbie to programming. I have a PHP website which works as
I was thinking about creating script that would do the following: Get all javascripts
While programming, the longest part is a build on my ASP.NET Website project is
I have a headline on a website I'm programming; let's say the headline says

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.