Check if POST is the same as the variable urls / myfile.php

0

I would like to do the following:

  • The user enters a POST | Done
  • PHP validates it | Done
  • Check if the POST is the same as the variable $password of a file urls/miarchivo.php .
  • In myfile.php I have:

    $password = "contraseñacorrecta";
    

    You should check if what is inside ""; is the same as the POST or return an error message.

    Thank you.

        
    asked by José Hernandez 14.04.2017 в 01:00
    source

    1 answer

    0

    Let's see if I understand correctly:

    You have a FORM that sends a data for POST ... and you want that FORM to tie the password input with a variable of a PHP file.

    If this is how I understand you, it's simple:

    Do an include of your file urls/miarchivo.php , hence the variable $ password that is in miarchivo.php is already accessible, in case there is a problem at most you can include it to become global ( global $password ) and ready is comparable.

    Let's see it in code (remember, this code is simple you should not use it for security and so on):

    <?php
         include("urls/miarchivo.php"); //se incluye el archivo donde se encuentra la variable $password
         $passwordDelForm = $_POST['password']; //esta es la contraseña que manda el form
    
         if($passwordDelForm != ""){ //se checa que no esté vacía
               if($passwordDelForm == $password){ //si empatan las variables
                    echo "Contraseña correcta";
               }else{ //si no empatan
                    echo "Error en la contraseña";
               }
          }else{ //si está vacía le mostramos un error
               echo "Error en la contraseña";
          }
    ?>
    

    You can corroborate after the include by tests printing the variable to see if it loads you and it does not have problems of accessibility, in case this is only as mentioned

    <?php
        global $password = "holamundo";
    ?>
    

    I hope you serve, greetings and luck.

        
    answered by 14.04.2017 в 02:47