reCaptcha errors

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

reCaptcha errors

Post by dlee » 2023-01-10 20:49

I followed the instructions in this article, https://bigprof.com/appgini/tips-and-tu ... -recaptcha and now I get this error:

Parse error: syntax error, unexpected 'if' (T_IF) in C:\xampp\htdocs\tcp\hooks\__global.php on line 8.

How do I fix this?
TD

Here is the code in __global.php file:

Code: Select all

<?php
	// For help on using hooks, please refer to https://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks

	// reCaptcha config
	include(__DIR__ . '/reCaptcha.config.php');
 
	// invalidate login if reCAPTCHA is invalid
	if ( Request::val('signIn')
  		 && Request::val('username')
  		 && Request::val('password')
  		 && !validRecaptcha() ) {
  		 unset($_REQUEST['username']);
  		 unset($_REQUEST['password']);
  		 unset($_REQUEST['signIn']);
  		 redirect('index.php?loginFailed=1');
	}
 
	function validRecaptcha() {
  	// get reCAPTCHA response from login form
  	$reCaptchaResponse = Request::val('g-recaptcha-response');
  	if(!$reCaptchaResponse) return false;
 
  	if(!function_exists('curl_init')) return false;
 
  	// send a POST request to Google's reCAPTCHA validation API endpoint
  	$ch = curl_init();
  	curl_setopt_array($ch, [
    	CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify',
    	CURLOPT_POST => true,
    	CURLOPT_POSTFIELDS => http_build_query([
      	'secret' => RECAPTCHA_SECRET_KEY,
      	'response' => $reCaptchaResponse,
    	]),
    	CURLOPT_RETURNTRANSFER => true,
  	]);
 
  	$googleRespJson = curl_exec($ch);
  	curl_close($ch);
 
  	// if error response, abort
  	if($googleRespJson === false) return false;
  	$googleResp = @json_decode($googleRespJson, true);
  	if($googleResp === null) return false;
 
  		return !empty($googleResp['success']);
	}

	function login_ok($memberInfo, &$args) {

		return '';
	}


User avatar
rngoda
Veteran Member
Posts: 124
Joined: 2020-02-05 16:00
Location: KENYA
Contact:

Re: reCaptcha errors

Post by rngoda » 2023-01-17 07:26

Try out this plugin: hassle free recaptcha integration among many other exciting features for your application https://ronthedev.gumroad.com/l/adminlteforappgini
I'm a software engineer specializing in web database application development for complex scalable web apps.

Buy AdminLTE Plugin For Appgini: HERE
Buy Cloud Storage Plugin For Appgini HERE

Checkout AdminLTE Plugin For Appgini Tutorials On Youtube

For support Email: [email protected] Whatsappp: Me Here

User avatar
a.gneady
Site Admin
Posts: 1280
Joined: 2012-09-27 14:46
Contact:

Re: reCaptcha errors

Post by a.gneady » 2023-01-18 07:52

rngoda wrote:
2023-01-17 07:26
Try out this plugin: hassle free recaptcha integration among many other exciting features for your application https://ronthedev.gumroad.com/l/adminlteforappgini
If this plugin addresses the specific issue mentioned in this post, please explain how it addresses it. If not, and this is just an ad for your plugin, I'll have to suspend your forum account if you do this again. This forum is intended to be a trusted place for AppGini users to get reliable answers to their questions not a marketplace for trying to sell unrelated products.
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

User avatar
a.gneady
Site Admin
Posts: 1280
Joined: 2012-09-27 14:46
Contact:

Re: reCaptcha errors

Post by a.gneady » 2023-01-18 08:04

dlee wrote:
2023-01-10 20:49
I followed the instructions in this article, https://bigprof.com/appgini/tips-and-tu ... -recaptcha and now I get this error:

Parse error: syntax error, unexpected 'if' (T_IF) in C:\xampp\htdocs\tcp\hooks\__global.php on line 8.

How do I fix this?
TD

Here is the code in __global.php file:
When I tried pasting your code into a text editor (I used sublime text, but any decent editor should be fine) to check it, and it turned out that many tabs were replaced by a null character <0xa0> so I guess this might be the reason for that error. Here is the code after cleanup of this character:

Code: Select all

<?php
	// For help on using hooks, please refer to https://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks

	// reCaptcha config
	include(__DIR__ . '/reCaptcha.config.php');

	// invalidate login if reCAPTCHA is invalid
	if ( Request::val('signIn')
		 && Request::val('username')
		 && Request::val('password')
		 && !validRecaptcha() ) {
		 unset($_REQUEST['username']);
		 unset($_REQUEST['password']);
		 unset($_REQUEST['signIn']);
		 redirect('index.php?loginFailed=1');
	}

	function validRecaptcha() {
		// get reCAPTCHA response from login form
		$reCaptchaResponse = Request::val('g-recaptcha-response');
		if(!$reCaptchaResponse) return false;

		if(!function_exists('curl_init')) return false;

		// send a POST request to Google's reCAPTCHA validation API endpoint
		$ch = curl_init();
		curl_setopt_array($ch, [
			CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify',
			CURLOPT_POST => true,
			CURLOPT_POSTFIELDS => http_build_query([
				'secret' => RECAPTCHA_SECRET_KEY,
				'response' => $reCaptchaResponse,
			]),
			CURLOPT_RETURNTRANSFER => true,
		]);

		$googleRespJson = curl_exec($ch);
		curl_close($ch);

		// if error response, abort
		if($googleRespJson === false) return false;
		$googleResp = @json_decode($googleRespJson, true);
		if($googleResp === null) return false;

		return !empty($googleResp['success']);
	}

	function login_ok($memberInfo, &$args) {

		return '';
	}
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

User avatar
rngoda
Veteran Member
Posts: 124
Joined: 2020-02-05 16:00
Location: KENYA
Contact:

Re: reCaptcha errors

Post by rngoda » 2023-01-18 14:53

a.gneady wrote:
2023-01-18 07:52
rngoda wrote:
2023-01-17 07:26
Try out this plugin: hassle free recaptcha integration among many other exciting features for your application https://ronthedev.gumroad.com/l/adminlteforappgini
If this plugin addresses the specific issue mentioned in this post, please explain how it addresses it. If not, and this is just an ad for your plugin, I'll have to suspend your forum account if you do this again. This forum is intended to be a trusted place for AppGini users to get reliable answers to their questions not a marketplace for trying to sell unrelated products.
Thank you for bringing this to my attention. I apologize if it seemed like I was trying to advertise my plugin in an inappropriate manner. To address the specific issue mentioned in this post, my plugin AdminLTE For Appgini allows users to easily setup reCAPTCHA for their login page, without having to touch code, the user simply keys in client key and secret and enables the reCAPTCHA feature. It is designed to work seamlessly with AppGini and can be easily integrated to provide a solution to the problem at hand. I understand and respect the purpose of this forum as a trusted place for AppGini users to get reliable answers to their questions and I assure you that in the future I will be more mindful of how I present my plugin.
I'm a software engineer specializing in web database application development for complex scalable web apps.

Buy AdminLTE Plugin For Appgini: HERE
Buy Cloud Storage Plugin For Appgini HERE

Checkout AdminLTE Plugin For Appgini Tutorials On Youtube

For support Email: [email protected] Whatsappp: Me Here

dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: reCaptcha errors

Post by dlee » 2023-01-18 20:57

OK, I replaced the bad code in /hooks/__global.php with the code you fixed and now I get this error when index.php loads:
Fatal error: Uncaught Error: Call to undefined function define() in C:\xampp\htdocs\tcp\hooks\reCaptcha.config.php:2 Stack trace: #0 C:\xampp\htdocs\tcp\hooks\__global.php(6): include() #1 C:\xampp\htdocs\tcp\lib.php(24): include_once('C:\\xampp\\htdocs...') #2 C:\xampp\htdocs\tcp\index.php(3): include_once('C:\\xampp\\htdocs...') #3 {main} thrown in C:\xampp\htdocs\tcp\hooks\reCaptcha.config.php on line 2
Other than this error message the screen is blank.

I have double checked that I did everything the mentioned article required just to be sure everything was as directed.

Let me know if you need anything to diagnose this and thank you trying to help!
TD

User avatar
a.gneady
Site Admin
Posts: 1280
Joined: 2012-09-27 14:46
Contact:

Re: reCaptcha errors

Post by a.gneady » 2023-01-23 13:17

Hmm ... define() is a pretty standard PHP function that doesn't need any special configuration to work. So, my guess is that the reCaptcha.config.php file you have might also include that null character <0xa0> issue. Try opening the file in a code editor (Sublime, Notepad++, VS Code, .. etc) and remove any occurrences of that character.
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

Post Reply