jeudi 11 mars 2021

Is there a way to do this without using the '_server' super globals? `PhraseBuilder::comparePhrases`

I am trying to create a basic captcha page for a site that I am working on. I am wondering if there is another way to do this without having to use super globals.

<?php                                                                                                                                                                                                                                                                
use Gregwar\Captcha\CaptchaBuilder;                                                                                                                         
use Gregwar\Captcha\PhraseBuilder;                                                                                                                          
                                                                                                                                                            
/* Captcha Creation */                                                                                                                                      
$captcha = new CaptchaBuilder();                                                                                                                            
$captcha->build();                                                                                                                                          
session_start();                                                                                                                                                                                                                                                                    
if ($_SERVER['REQUEST_METHOD'] == 'POST') {                                                                                                                 
// Checking that the posted phrase match the phrase stored in the session                                                                                   
if (isset($_SESSION['phrase']) && PhraseBuilder::comparePhrases($_SESSION['phrase'], $_POST['phrase'])) {                                                   
  header("Location: index.php");                                                                                                                            
    //echo "<h1>Captcha is valid !</h1>";                                                                                                                   
    } else {                                                                                                                                                
    echo "<h1>Captcha is not valid!</h1>";                                                                                                                  
    }                                                                                                                                                       
    // The phrase can't be used twice                                                                                                                       
  unset($_SESSION['phrase']);                                                                                                                               
}                                                                                                                           
?>

Any suggestions would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire