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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:18:26+00:00 2026-06-18T00:18:26+00:00

i need help for limiting login attempt of the user. this is my code.

  • 0

i need help for limiting login attempt of the user. this is my code.

$login = login($username, $password);
        if($login === false) {
            if(isset($_COOKIE['login'])){
                      if($_COOKIE['login'] < 3){
                           $attempts = $_COOKIE['login'] + 1;
                           setcookie('login', $attempts, time()+60*10); //set the cookie for 10 minutes with the number of attempts stored
                           $errors[] = 'That username/password combination is incorrect!';
                      } else{
                           echo 'You are banned for 10 minutes. Try again later';
                      }
            } else {
                   setcookie('login', 1, time()+60*10); //set the cookie for 10 minutes with the initial value of 1
             }

        } else {        
            $_SESSION['user_id'] = $login;
            header('Location: ../../home.php');
            exit();
        }

it looks right for me but it just wont work. the user could still access his/her account even after attempting 3 login.

  • 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-18T00:18:27+00:00Added an answer on June 18, 2026 at 12:18 am

    Use an SQL database, im currently working on a snippet of code, give me about an hour and ill throw an exampl up for you


    PHP:

    <?php
    $host = "";//Host name
    $username = "";//MYSQL username
    $password = "";//MYSQL password
    $db_name = "";//Database name
    $tbl_name = "";//Name of login table
    $bl_name2 = "";//Name of table to store IP if attempt is incorrect
    
    //connect to server and select database
    try{
    $conn = new PDO('mysql:host='.$host.';dbname='.$db_name.'',$username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);}
    catch(PDOException $e){
    echo 'ERROR: ' . $e->getMessage();}
    
    //get users ip next, as this is for a log in, this example will show for username and pass also
    $userIP = $_SERVER['REMOTE_ADDR'];
    $userPassword = $_POST['passwordfromform'];
    $userUsername = $_POST['usernamefromform']
    
    if(empty($userUsername) && empty($userPassword)){
    die("You must enter a username and password");
    }
    
    //check for log in excess
    $checkSql="
    SELECT * FROM ".$tbl_name2."
    WHERE PostersIP = '".$userIP."'
    ";
    $stmt = $db->query($checkSql);
    $row_count = $stmt->rowCount();
    if($rowcount >= 7){//change this number to reflect the nuber of login chances
    die("You have tried to log in too many times");
    }
    
    //check to log in
    $insertSql = "
    SELECT * FROM ".$tbl_name."
    WHERE USERNAME = '".$userUsername."'
    AND PASSWORD = '".$userPassword."'";
    
    //execute check query
    $result = $conn->query($insertSql);
    if($result != false){
    echo "Username and Password were correct!";//link to correct page
    }
    else{
    $incorrectSql="
    INSERT INTO ".$tbl_name2."
    (PostersIP) VALUES 
    ('".$userIP."')";
        $result2 = $conn->query($incorrectSql);
         if($result2 != false){
              die("You entered an invalid username or password, your attempt has been stored.");
            }
    die("Error inserting data");
    }
    ?>
    

    I did not test this live, so there may be a few flaws, however i commented it pretty well for ya. you do need a second table to store user submission ips. this is a VERY messy way to do this. Im very sure there are better ways to do it, but theres my 10 minute solution 🙂

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

Sidebar

Related Questions

need help on this one: here's a my sample code, i would like to
Need help on this following code. the problem is it only trigger the last
Need Help - I have some code for Logout like this public void logoutFromFacebook()
Need help writing a script downloads data from google insight using c# this is
I need help with one ajax function This is raw page setup. Page will
Need help compiling in C. When using GCC at home (Windows, 3.4.5), the code
Need help with this error. Can't see what's wrong. Error: Warning: mysql_query() expects parameter
Need help with below code. I am trying to query from same table and
Need help to convert code from asp control to input type to fetch file
Need help with deleting call log from multi numbers, using the following code i

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.