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

  • Home
  • SEARCH
  • 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 7666589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:52:18+00:00 2026-05-31T14:52:18+00:00

In my comments system, I noticed a small security bug. In the few seconds

  • 0

In my comments system, I noticed a small security bug. In the few seconds that it takes a page to load, a user can click the “post” button more than once submitting several comments to the database instead of one. I managed to fix this with a simple Javascript input disable thingy, but then I remembered that people could easily edit this using Firebug or Inspect Element.

Is there some sort of PHP solution to this? I’m pretty new, so please don’t go speaking technical words.

Thanks. 🙂

  • 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-31T14:52:20+00:00Added an answer on May 31, 2026 at 2:52 pm

    The most simple solution is to store all data in a session, which you need to determine that comment is unique. A php session is active as long as a user stays on your website, another visitor will have another session. That means, to determine if your visitor clicked the button twice, you only need a) the message and b) on which post (I assume) s/he commented.

    An example:

    session_start();
    
    // This is something you already have, sort-of
    $message = $_POST['message']; // Message from user
    $post    = $_GET['id']        // Id of post to which he commented
    
    if (isset($_SESSION['message']
     && isset($_SESSION['id']
     && $message === $_SESSION['message']
     && $post === $_SESSION['id'])
    {
      // We found out the user has already posted this
      echo 'Error: you clicked twice!';
      exit;
    }
    
    // Process message here as you already do
    
    // Store now this just posted message in a session
    $_SESSION['message'] = $message;
    $_SESSION['id']      = $post;
    

    With this method you are sure there is no data persisted in the server twice. However, you still need to disable that button with javascript since you cannot disable that button with php as long as your request is going on.

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

Sidebar

Related Questions

I am making a comments system in which i can accept user input with
I have a system of comments, and each comment has a button that normally
I have a system where registered users can vote up/vote down comments for a
I'm trying to write a commenting system, where people can comment on other comments,
Stackoverflow has a nifty badge system. One thing I noticed is that badges are
Have you noticed that for some methods in the system assemblies, the .NET Reflector
I've noticed that there are awvully few programming tutorials in my native language (Latvian).
I would like to create a pagination system for comments in my website.So far,
I am using a login system. When I navigate to comments/index.php without logging in,
XmlSerializer serializer = new XmlSerializer(typeof(IxComment)); System.IO.StringWriter aStream = new System.IO.StringWriter(); serializer.Serialize(aStream,Comments); commentsString = aStream.ToString();

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.