Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
Unsetting Superglobal Variable Properly

I've recently switched from Dreamweaver to Netbeans and, with the built-in accountability for clean code, I've realized I have some work to do in writing proper/clean code.

Currently, I'm trying to adjust from accessing SuperGlobals (such as $_POST) directly. For this question, specifically, I am trying to figure out how to handle unsetting a SuperGlobal variable temporarily.

$sampleArray = ["Designer_Name" => "someName",
            "Designer_Key" => "someName's UID",
            "Designer_Store" => "someStoreName",
            "Group_Name" => "someGroupName",
            "Dropbox_Key" => "someUID"
            ];

Normally, I might do something like this:

unset($_POST['Dropbox_Key']);

In this particular problem, I am trying to use short amounts of code. I know that I can filter/sanitize each element of the array and assign it to a variable, but since the $_POST array is not user-input, I'm not too concerned with that.

With this array, I'll be inserting the entire array into a database table, minus the last element. I don't need 'Dropbox_Key' for the same table as the rest of the array. I will use that element later for another table.

The insert code would look like this:

$insert = $dbs->insert('sometable', filter_input_array(INPUT_POST));

So, the question I am asking is, despite it being easier to ignore the netbeans warnings of accessing SuperGlobals, is there some current/cleaner way to do what I intend (the unsetting of the $_POST element), or is ignoring the warning the best way to go here?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The reason we use filter_input() on super global input's like $_POST is because it tends to be user entered data we cannot trust. By filtering we can escape and sanitize the inputs to help prevent XSS (cross-site scripting) and SQLinjections.

In the case of un-setting super global's in your own code there is no risk posed (You are in control of your code), so we can safely unset directly unset($_POST['Dropbox_Key']);

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda