Captcha icon indicating copy to clipboard operation
Captcha copied to clipboard

Can you implement phrase building and checking without using super globals?

Open anoduck opened this issue 3 years ago • 0 comments

I have ran into a sticky wicket where I am attempting to add a simple captcha page to my site and currently within the site folder super globals are disabled. So, I am getting all sorts of errors. I attempted to enable super globals programmatically just for the needed phrase and it is giving me the error Call to a member function enable_super_globals() on null. So I was wondering if there was another way to use PhraseBuilder::comparePhrases that does not entail use of the _server global?

Here is the important block of code where I am running into issues.


$captcha = new CaptchaBuilder();
$captcha->build();
session_start();
global $request;
global $config;
$request->enable_super_globals();
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']);
};
$request->disable_super_globals()

I know this is not technically an "issue", but figured it would not hurt asking for a little help sorting this one out.

anoduck avatar Mar 11 '21 22:03 anoduck