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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:42:25+00:00 2026-06-01T21:42:25+00:00

I want to prevent my script, from being flooded – if user hit F5

  • 0

I want to prevent my script, from being flooded – if user hit F5 it is executing the script every time.

I want to prevent from this and allow one script execution per 2 seconds, is there any solution for that?

  • 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-01T21:42:27+00:00Added an answer on June 1, 2026 at 9:42 pm

    You can use memcache to do this ..

    Simple Demo Script

    $memcache = new Memcache ();
    $memcache->connect ( 'localhost', 11211 );
    $runtime = $memcache->get ( 'floodControl' );
    
    if ((time () - $runtime) < 2) {
        die ( "Die! Die! Die!" );
    } 
    
    else {
        echo "Welcome";
        $memcache->set ( "floodControl", time () );
    }
    

    This is just a sample code .. there are also other thing to consider such as

    A. Better IP address detection (Proxy , Tor )

    B. Current Action

    C. Maximum execution per min etc …

    D. Ban User after max flood etc

    EDIT 1 – Improved Version

    Usage

    $flood = new FloodDetection();
    $flood->check();
    
    echo "Welcome" ;
    

    Class

    class FloodDetection {
        const HOST = "localhost";
        const PORT = 11211;
        private $memcache;
        private $ipAddress;
    
        private $timeLimitUser = array (
                "DEFAULT" => 2,
                "CHAT" => 3,
                "LOGIN" => 4 
        );
        private $timeLimitProcess = array (
                "DEFAULT" => 0.1,
                "CHAT" => 1.5,
                "LOGIN" => 0.1 
        );
    
        function __construct() {
            $this->memcache = new Memcache ();
            $this->memcache->connect ( self::HOST, self::PORT );
        }
    
        function addUserlimit($key, $time) {
            $this->timeLimitUser [$key] = $time;
        }
    
        function addProcesslimit($key, $time) {
            $this->timeLimitProcess [$key] = $time;
        }
    
        public function quickIP() {
            return (empty ( $_SERVER ['HTTP_CLIENT_IP'] ) ? (empty ( $_SERVER ['HTTP_X_FORWARDED_FOR'] ) ? $_SERVER ['REMOTE_ADDR'] : $_SERVER ['HTTP_X_FORWARDED_FOR']) : $_SERVER ['HTTP_CLIENT_IP']);
        }
    
        public function check($action = "DEFAULT") {
            $ip = $this->quickIP ();
            $ipKey = "flood" . $action . sha1 ( $ip );
    
            $runtime = $this->memcache->get ( 'floodControl' );
            $iptime = $this->memcache->get ( $ipKey );
    
            $limitUser = isset ( $this->timeLimitUser [$action] ) ? $this->timeLimitUser [$action] : $this->timeLimitUser ['DEFAULT'];
            $limitProcess = isset ( $this->timeLimitProcess [$action] ) ? $this->timeLimitProcess [$action] : $this->timeLimitProcess ['DEFAULT'];
    
            if ((microtime ( true ) - $iptime) < $limitUser) {
                print ("Die! Die! Die! $ip") ;
                exit ();
            }
    
            // Limit All request
            if ((microtime ( true ) - $runtime) < $limitProcess) {
                print ("All of you Die! Die! Die! $ip") ;
                exit ();
            }
    
            $this->memcache->set ( "floodControl", microtime ( true ) );
            $this->memcache->set ( $ipKey, microtime ( true ) );
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to prevent iframe elements from triggering the OnDocumentComplete event every time. For
I want to prevent my asp.net / c# 2008 web pages from being cached
I have an HTML textarea element. I want to prevent a user from entering
I want to prevent my iframe from being cached. The first page isn't a
I want to prevent the # from being used because I'm using jQuery to
I want to prevent the user from going back to the shell prompt by
Let's say i have an image uploader script, i want to prevent the upload
I want to prevent users from commenting on deleted threads. I've set a variable
What solutions do I have if I want to prevent the UI from freezing
The MSDN documentation on WebBrowser Customization explains how to prevent new windows from being

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.