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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:51:54+00:00 2026-06-09T07:51:54+00:00

If you post a html form with inputs having names ending with [], php

  • 0

If you post a html form with inputs having names ending with [], php will automatically make these $_POST-values into an array.

For example, without brackets:

<input name="email" value="a" />

var_dump($_POST["email"])    
//string 'a' (length=1)

With brackets:

<input name="email[]" value="a" />
<input name="email[]" value="b" />

var_dump($_POST["email"])    
//array
//  0 => string 'a' (length=1)
//  1 => string 'b' (length=1)

My problem is that previously i didn’t know about this so i’ve been coding my website with the assumption that $_POST-variables always are of type string. Naturally i perform standard input validation but only assuming that the variables already are strings.

So what if a hacker takes one of my normal inputs, like <input name="email" .../> and posts it with the brackets after. Then my code fetching $_POST[“email”] would be an array!

I could imagine there are cases where this would be a security problem, for example startsWith-function could work on both strings and arrays. I haven’t researched the full implications of it and i don’t want to either, i just want to disable the function completely so i can trust all $_POST-variables to always be strings.

Is there any way to disable this function globally or is the only option to find-replace all and add a (string)-cast in front of every access of $_POST?

  • 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-09T07:51:56+00:00Added an answer on June 9, 2026 at 7:51 am

    You could just loop through the POST array, and fix them this way.
    But, since you said you don’t ever plan to need this, why not just loop through the _POST array, check if anything is a non-string, and then just throw an exception? No need to give the hypothetical hacker a nice fallback or workaround 🙂

    foreach($_POST as $val) {
       if (!is_string($val)) {
          throw new InvalidArgumentException('POST arguments should be strings only');
       }
    }
    

    I find the best way to deal with such issues is to be strict, and throw exceptions for cases where a client (browser/evil guy) is clearly messing around with stuff 😉

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

Sidebar

Related Questions

I was wondering if converting POST input from an HTML form into html entities,
I have an HTML form: <form action='process.php' method='post'> <input type='checkbox' name='check_box_1' /> Check me!<br>
I have this HTML: <form action='uploadhandle.php' method='POST' enctype=multipart/form-data> <input type='file' class='fileinput' id='photo1' name='photo1'> <input
I have a post html form, and the action is index.php, which is the
I want to post some values from a simple HTML form, validate them with
I'm having a bit of an issue with PHP emailing from a HTML form.
form html: <form action='/register/' method = 'post'>{% csrf_token %} ... <label>Avatar: </label><input type='file' name='avatar'
Situation is simple: I post a plain HTML form with a textarea. Then, in
When i use an html form to post a file, how do i address
I have a html form with the data by this post method 'form id='form1'

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.