dimanche 23 juin 2019

compare variable with user input in php always returns false

I'm making a verification page that compares two variables

the first one is a random code that have been generated previously from a python script and took the result to php variable under the name $code example of the output (8063D0A7) it is an 8 characters of numbers and letters

the second one is the user input ($verf)

when the user clicks submit ($code) and ($verf) should be compared if it is true then transfer to other page if not then try again will be showed

I have tried a lot of ways but it always shows false in any case and any input

<?php
session_start(); ///starts a session and getting the variables from another page 

echo "E-mail has been sent to " ;
echo $_SESSION['email'];  ///gets $email from another page


echo $email , "   ";
echo $_SESSION['code'];  ///gets the $code from another page


$email = escapeshellarg($_SESSION['email']);  ///make an arg to put in bash script


$code = escapeshellarg($_SESSION['code']);


$addr = shell_exec("./test.sh $email $code"); ///execute bash script to send $code to $email


?>
<!DOCTYPE HTML>  
<html>
<body>  
<h2>E-mail Verfication</h2>
<form method="post" action="">  
Name: <input type="string" name="verf" value="">
  <br><br>
  <input type="submit" name="submit2" value="Submit">  
</form>

<?php
if (isset($_POST['submit2'])) {
    $verf = $_POST['verf'];
    if ($verf == $code) {
        echo "Correct!";
         header('Location: 12.php');
    } else { 
        echo "Wrong!";

    }

} else {
    echo "please fill the verification";
}



 echo $verf;
 echo $code;

?>

</body>
</html>

i think there is a problem identifying the variables for example takes $code as a string and $verf as an other type of input so it will always be false i don't know i'm new to php help PLZ .. :D

Aucun commentaire:

Enregistrer un commentaire