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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:52:15+00:00 2026-06-03T18:52:15+00:00

Is there a way to ensure the $_POST data my code received came from

  • 0

Is there a way to ensure the $_POST data my code received came from my form and not an outside influence. Basically I don’t want someone to be able to spoof a $_POST to a universally available page such as account creation. The account creation page is accessible by any user, but I want to ensure only the data submitted by my account_creation form is what gets processed.

The only thing I could think of was initiating a $_SESSION, and then supplying the session_id to the form using a hidden input. Upon $_POST the value of the hidden input would then be matched against the current session_id.

If there is a better method to achieve this result? If there is I look forward to hearing it.

  • 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-03T18:52:22+00:00Added an answer on June 3, 2026 at 6:52 pm

    You cannot ensure that data came from a form. A POST request is just a POST request, it can be generated in any number of ways. An HTML form is just one of those ways that’s very user friendly. Your server needs to validate whether the data received via the POST request is valid or not and whether to act on it or not.

    Having said that, there are things that can help you to restrict and validate the data that is being submitted. First of all, require that a user is logged in using (session) cookies. That eliminates random requests by anonymous users. Secondly, you can embed a token as a hidden field into the form which you also save into the user’s session. The POST request needs to contain that token in order to be valid. The token is simply a pseudo-random string.
    You can enhance this by preparing a hash of the form fields that you expect the user to submit. If the form value should be read-only, you can include the value into the hash as well. E.g.:

    $rand = md5(mt_rand());
    $hash = sha1('lastname:firstname:email:' . $rand);
    
    $_SESSION['rand'] = $rand;
    $_SESSION['hash'] = $hash;
    
    // on form submit:
    
    $keys = array_keys($_POST);
    $checkHash = sha1(join(':', $keys) . ':' . $_SESSION['rand']);
    if ($checkHash != $_SESSION['hash']) {
        die('Form submission failed token validation');
    }
    

    That’s just a quick example, you’ll probably want to sort the keys alphabetically to make sure you’ll get the same hash etc. It demonstrates the concept of the user needing to have a unique token for each request though which prevents tempering with forms and submitting more or less data than wanted.

    This still does not mean that a user actually used your form to submit the data though.

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

Sidebar

Related Questions

Is there a way to ensure all created subprocess are dead at exit time
Is there any way to ensure that a class posts a particular NSNotification? (I
In the 1.6 API, is there a way to ensure that the onStart() method
Is there a way to test to see if javascript is enabled to ensure
Is there way in next piece of code to only get the first record?
is there way how to get name ov event from Lambda expression like with
Is there any way I can run this code with async:false? I notice the
Is there a way to call the javascript form submit() function or the JQuery
Is there a way to ensure that when a user views my Flex app,
Is there a way to make a field required for form submission? I can

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.