I am learning PHP and trying to compare a random string with a input from a user.
I have this code for the random string:
$rand = substr(uniqid('', true), -5);
$_SESSION['random'] = $rand;
and this code prints the random string.
<?php echo $_SESSION['random']; ?>
This is the input from the user:
<input type="text" placeholder="Typ string" name="rand" required>
I am now trying to compare the random string with the input from the user:
if (isset($_POST['rand']) and $_POST['rand'] !='') {
if ($_SESSION['random'] == $_POST['rand']) {
Do some stuff;
}}
Can someone please help me with this?
Aucun commentaire:
Enregistrer un commentaire