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

The Archive Base Latest Questions

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

I’m going to use PHP in my example, but my question applies to any

  • 0

I’m going to use PHP in my example, but my question applies to any programming language.

Whenever I deal with forms that can be filled out by users who are not logged in (in other words, untrusted users), I do several things to make sure it is safe to store in the database:

  • Verify that all of the expected fields are present in $_POST (none were removed using a tool such as Firebug)
  • Verify that there are no unexpected fields in $_POST. This way, a field in the database doesn’t accidentally get written over.
  • Verify that all of the expected fields are of the expected type (almost always “string”). This way, problems don’t come up if a malicious user is tinkering with the code and adds “[]” to the end of a field name, thus making PHP consider the field to be an array and then performing checks on it as though it were a string.
  • Verify that all of the required fields were filled out.
  • Verify that all of the fields (both required and optional) were filled out correctly (for example, email addresses and phone numbers are in the expected format).
  • Related to the previous item, but worthy of being its own item: verify that fields that are dropdown menus were submitted with values that are actually in the dropdown menu. Again, a user could tinker with the code and change the dropdown menu to be anything they want.
  • Sanitize all fields just in case the user intentionally or unintentionally included malicious code.

I don’t believe that any of the above things are overkill because, as I mentioned, the user filling out the form is not trusted.

When it comes to admin backends, however, I’m not sure all of those things are necessary. These are the things that I still consider to be necessary:

  • Verify that all of the required fields were filled out.
  • Verify that all of the fields (both required and optional) were filled out correctly (for example, email addresses and phone numbers are in the expected format).
  • Sanitize all fields just in case the user intentionally or unintentionally included malicious code.

I’m considering dropping the remaining items in order to save time and have less code (and, therefore, more readable code). Is that a reasonable thing to do or is it worthwhile to treat all forms equally regardless of whether or not they are being filled out by a trusted user?

These are the only two reasons I can think of for why it might be wise to treat all forms equally:

  • The trusted user’s credentials might be found out by an untrusted user.
  • The trusted user’s machine could be infected with malware that messes with forms. I have never heard of such malware and doubt that this is something to be really be worried about, but it is something to consider anyway.

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-26T02:31:18+00:00Added an answer on May 26, 2026 at 2:31 am

    Without knowing all the details, it’s hard to say.

    However, in general this feels like a situation where code re-use should be possible. In other words, it feels like this boiler-plate form validation shouldn’t need to be re-written for each unique form. Instead, I would aim to create some reusable external class that could be used for any form.

    You mentioned PHP and there are already lots of form validation classes available:

    http://www.google.com/search?gcx=w&sourceid=chrome&ie=UTF-8&q=form+validation+php+class

    Best of luck!

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

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.