After typing in username and password I redirect the user to a page where a text message is send that he has to fill in (for some not a good 2FA but thats not the discussion :)
What should happen is this: webpage gets loaded with a form and a text message is send to the user at the same time. User types in the code he received in the text message. Codes are compared and user gets redirected.
The part of the text sending works but after that something goes wrong. I logged everything and see that the comparison itself works but different values are compared as another (second) text is send. I do not know why this is? Why is it sending a second text after the post is submitted?
<?php
// Initialize the session
session_start();
// Check if the user is already logged in, if yes then redirect him to welcome page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: index.php");
exit;
}
error_reporting(E_ALL);
error_reporting(-1);
ini_set('error_reporting', E_ALL);
ini_set('error_log', 'error.log');
// SMS script
$otp = rand(100000,999999);
error_log($otp);
$mobiel = $_SESSION["mobielnummer"] ;
$tekst = "Je+beveiligingscode+is+:+".$otp."";
$api_key = '****';
$verzoek = "https://*****************" ;
$xml = file_get_contents($verzoek);
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Check if bevcode is empty
if(!empty(trim($_POST["bevcode"]))){
$bevcode = trim($_POST["bevcode"]);
// compare vars
if ($bevcode === $otp) {
$_SESSION["smsoke"] = true;
header("location: home.php");
}
else {
$login_err = "Dit is een onjuiste code.";
error_log($bevcode);
error_log($otp);
}
}
}
?>