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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:07:16+00:00 2026-05-19T15:07:16+00:00

How to prevent USER from doing automated posts/spam? Here is my way of doing

  • 0

How to prevent USER from doing automated posts/spam?

Here is my way of doing it, new php session for each page request, which has its own limitations, no multitabing.

I used new session for each page as defense against both CSRF and automated attacks. Lets say we have forum that uses AJAX to post threads and its validated by PHP SESSION.

add_answer.php?id=123

<?php
if(!is_ajax()){// function that determines whether the request is from ajax (http header stuff)
$_SESSION['token'] = md5(rand());
}
//some ajax request to ajax.php?id=123
?>

ajax.php?id=123

<?php
if($_SESSION['token'] == $_GET['token']){
echo 'MYSQL INSERT stuff';
}else{
echo 'Invalid Request';
}
?>

Every thing works fine until the user opens page.php?id=456 on another tab, the ajax returns ‘invalid request’ on ajax.php?id=123 This is related to another question I asked. They suggested to use only one session hash all the time, until he/she logs out – only then the session is regenerated. If the token is the same USER could simply bypass it and do the automated attacks. Any ideas on that?

Anyhow whats your way of preventing Automated AJAX attacks?

PS:

  1. Dont torture users with captchas.
  2. Google failed to show me something useful on this.
  3. Take this as a challenge.
  4. Or at least vote the answers of the experts which you think is brilliant way of doing this
  • 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-19T15:07:16+00:00Added an answer on May 19, 2026 at 3:07 pm

    It sounds like your objection to letting the session stay open as long as the browser is open is the issue of automated attacks. Unfortunately, refreshing the token on each page load only deters the most amateur attackers.

    First, I assume we’re talking about attacks specifically targeted at your site. (If we’re talking about the bots that just roam around and submit various forms, not only would this not stop them, but there are far better and easier ways to do so.) If that’s the case, and I’m targeting my site, here’s what my bot would do:

    1. Load form page.
    2. Read token on form page.
    3. Submit automated request with that token.
    4. Go to step 1.

    (Or, if I investigated your system enough, I’d realize that if I included the “this is AJAX” header on each request, I could keep one token forever. Or I’d realize that the token is my session ID, and send my own PHPSESSID cookie.)

    This method of changing the token on each page load would do absolutely nothing to stop someone who actually wanted to attack you all that badly. Therefore, since the token has no effect on automation, focus on its effects on CSRF.

    From the perspective of blocking CSRF, creating one token and maintaining it until the user closes the browser seems to accomplish all goals. Simple CSRF attacks are defeated, and the user is able to open multiple tabs.

    TL;DR: Refreshing the token once on each request doesn’t boost security. Go for usability and do one token per session.


    However! If you’re extremely concerned about duplicate form submissions, accidental or otherwise, this issue can still easily be resolved. The answer is simple: use two tokens for two different jobs.

    The first token will stay the same until the browser session ends. This token exists to prevent CSRF attacks. Any submission from this user with this token will be accepted.

    The second token will be uniquely generated for each form loaded, and will be stored in a list in the user’s session data of open form tokens. This token is unique and is invalidated once it is used. Submissions from this user with this token will be accepted once and only once.

    This way, if I open a tab to Form A and a tab to Form B, each one has my personal anti-CSRF token (CSRF taken care of), and my one-time form token (form resubmission taken care of). Both issues are resolved without any ill effect on the user experience.

    Of course, you may decide that that’s too much to implement for such a simple feature. I think it is, anyway. Regardless, a solid solution exists if you want it.

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

Sidebar

Related Questions

I'm doing things as said in How do I prevent the user from changing
Is there any way I can prevent the user from hitting the return key
We want to prevent the user from doing anything except selecting a folder. We
I'm trying to prevent user from inserting * in a textbox. This is what
Is it possible to prevent user from writing letters to a textbox (i.e. force
In wpf how can i prevent user from moving the windows by dragging the
After processing form from POST I should redirect, to prevent user from hitting back.
How can I prevent a user from tabbing into a field (comboxbox)?
On my forms I prevent the user from submitting the form by clicking enter
My question is how can I prevent the user from closing the application? .

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.