DragonPrime - LoGD Resource Community
Welcome Guest
  • Good morning, Guest.
    Please log in, or register.
  • June 25, 2018, 10:39:59 AM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
Search

Pages: 1 [2] 3   Go Down
  Print  
Author Topic: reCAPTCHA anti-spam for petition.php  (Read 6519 times)
0 Members and 2 Guests are viewing this topic.
Megan|SaraBeth
Mod God
*****
Offline Offline

Posts: 1052



View Profile WWW
« Reply #15 on: February 15, 2018, 01:49:11 PM »

This module needs updating for recaptcha v2. V1 is being discontinued.
Logged

Aeolus
Mod God
*****
Offline Offline

Posts: 1878


You're welcome.


View Profile WWW
« Reply #16 on: February 17, 2018, 08:32:02 AM »

This module needs updating for recaptcha v2. V1 is being discontinued.

We thank you for your offer to update the code yourself for the good of the community.
Logged

Nightborn
Captain of the Guard
***
Offline Offline

Posts: 215


View Profile WWW
« Reply #17 on: March 26, 2018, 09:55:10 AM »

You can drop most of the code and the library here though... here is a guide (google search for "recaptcha php", 3rd hit.

https://www.kaplankomputing.com/blog/tutorials/recaptcha-php-demo-tutorial/
Logged
Megan|SaraBeth
Mod God
*****
Offline Offline

Posts: 1052



View Profile WWW
« Reply #18 on: March 29, 2018, 05:58:57 PM »

I have sat here and tried to figure out how to change the code properly to affect v2. Its all written for v1 and that link you gave me looks way different in code than v1 does. I wouldnt even know what to change and where so I dont break something. Points in the right direction would be nice. This stuff is confusing me.
Logged

Aeolus
Mod God
*****
Offline Offline

Posts: 1878


You're welcome.


View Profile WWW
« Reply #19 on: March 30, 2018, 05:19:57 PM »

I have sat here and tried to figure out how to change the code properly to affect v2. Its all written for v1 and that link you gave me looks way different in code than v1 does. I wouldnt even know what to change and where so I dont break something. Points in the right direction would be nice. This stuff is confusing me.

So, is this another "tell me exactly what to copy and where to paste it" thing?
Logged

TGTarheel
Codemeister
****
Offline Offline

Posts: 450


View Profile
« Reply #20 on: March 30, 2018, 10:58:20 PM »

Taking a quick glance at this...and at petition.php for version 1.1.2 ...my take would be to take the following code and paste it between lines 95 and 96 in /lib/petition/petition-default
Code:
$response = $_POST["g-recaptcha-response"];
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => 'YOUR_SECRET',
'response' => $_POST["g-recaptcha-response"]
);
$options = array(
'http' => array (
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context  = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success=json_decode($verify);
if ($captcha_success->success==false) {
echo "<p>You are a bot! Go away!</p>";
} else if ($captcha_success->success==true) {

Doing it in that place would cause the else if curlies to match up properly so you should not get a parsing error.

The PHP code is right where Aeolus pointed to. (LOL, edit, Nightborn is the one who pointed...sorry Nightborn!!)

I just took out the first three lines of the posted PHP code since these items are already asked for within petition.php

i did not test this out myself...but you could try this...it should work or at least get you close.  I think.

Not the world's greatest at this myself, but it looks like it at least makes sense.

You do not get the submit button unless you pass the CAPTCHA the way I see it.

You will need one more close curly at the very end of the code, though.  In addition to what I posted above.

Right above the very last line of code.

I am not 100 percent certain, since I really just glanced at this...it could be the code above might be better in a different place within that file...but the file you want it in is /lib/petition/petition-default.php

Sarabeth, you should get yourself Notepad + or a similar code program...it helps with parsing the open and close curlies.
« Last Edit: April 01, 2018, 10:55:08 AM by TGTarheel » Logged
Megan|SaraBeth
Mod God
*****
Offline Offline

Posts: 1052



View Profile WWW
« Reply #21 on: April 01, 2018, 10:10:20 AM »

I have sat here and tried to figure out how to change the code properly to affect v2. Its all written for v1 and that link you gave me looks way different in code than v1 does. I wouldnt even know what to change and where so I dont break something. Points in the right direction would be nice. This stuff is confusing me.

So, is this another "tell me exactly what to copy and where to paste it" thing?

I wouldnt have posted here at all if I figured it out or could figure it out. I only post when Im stuck. Instead of being difficult, help would be nice. Im going to try what TGTarheel said and see.
Logged

TGTarheel
Codemeister
****
Offline Offline

Posts: 450


View Profile
« Reply #22 on: April 01, 2018, 10:48:51 AM »

I have sat here and tried to figure out how to change the code properly to affect v2. Its all written for v1 and that link you gave me looks way different in code than v1 does. I wouldnt even know what to change and where so I dont break something. Points in the right direction would be nice. This stuff is confusing me.

So, is this another "tell me exactly what to copy and where to paste it" thing?

I wouldnt have posted here at all if I figured it out or could figure it out. I only post when Im stuck. Instead of being difficult, help would be nice. Im going to try what TGTarheel said and see.

Let me know, SaraBeth.  I am not terribly good at this stuff either, and I often run into the same problem of not really getting help...if what you want is to be spoon-fed answers.  That being said...I think Nightborn here did point to some decent code on this.  But he didn't really tell you what to do with it.  

I can appreciate what some are trying to do...to help you learn...but...often, they don't give you enough to really be helpful...and sometimes, some here are not very nice in how they go about it.

I make no guarantees on what I posted, I really did just glance at it.  But I think it would at least be on the right track.  I am reasonably sure that your coding changes will want to be in the file I specified though, if that is any help to you.

If it does not work, then perhaps we two could brainstorm on this a bit more and see if we can figure it out between us.  Two heads are better than one.
Then again, we might be the blind leading the blind.  LOL.
« Last Edit: April 01, 2018, 10:55:33 AM by TGTarheel » Logged
Megan|SaraBeth
Mod God
*****
Offline Offline

Posts: 1052



View Profile WWW
« Reply #23 on: April 01, 2018, 11:37:00 AM »

I really think its better to just edit the module that is here because you cant put a div code in that file you told me to edit. I got an error and you need it in there to display the widget and also you need another code that would have to be applied to EVERY template if you didnt edit this mod. I think we just need someone to give pointers.
Logged

TGTarheel
Codemeister
****
Offline Offline

Posts: 450


View Profile
« Reply #24 on: April 01, 2018, 02:12:10 PM »

I really think its better to just edit the module that is here because you cant put a div code in that file you told me to edit. I got an error and you need it in there to display the widget and also you need another code that would have to be applied to EVERY template if you didnt edit this mod. I think we just need someone to give pointers.

Well, there ya have it.
either you can't do what needs to be....or, as I suggested, my placement in that file isn't quite right.

I am not sure why it would not work, exactly...so now would be a ood time for you to tell us what sort of errors you got...did you get a call stack?
Logged
Megan|SaraBeth
Mod God
*****
Offline Offline

Posts: 1052



View Profile WWW
« Reply #25 on: April 01, 2018, 03:42:07 PM »

Nope. When I placed it exactly how you said all it did was post the you are a bot part at the top of the page. No widget or error.
Logged

TGTarheel
Codemeister
****
Offline Offline

Posts: 450


View Profile
« Reply #26 on: April 01, 2018, 04:52:45 PM »

So there is not a problem with the code itself then....it just is not doing what we want.  This means there is something that needs to be worked on.

Not sure what...I have never worked with CAPTCHA.

Can we have some examples of modules/files where CAPTCHA works with the old version...it could give some clues as to how to proceed.

The code itself is not in error in any way, it recognizes everything.

Th e problem is that it doesn't do what we want....meaning it needs to go somewhere else...or some variable is not reading correct or setting correct.

My point being...sometimes...what we just got...is more progress than it looks like.

W just need to figure out why you are failing the variable...without being given a chance to pass it.

For that, I would try to Google usage of CAPTCHA in HTML...since this is likely to be an HTML function, as it displays in a web browser...and not necessarily PHP
« Last Edit: April 01, 2018, 05:04:57 PM by TGTarheel » Logged
Aeolus
Mod God
*****
Offline Offline

Posts: 1878


You're welcome.


View Profile WWW
« Reply #27 on: April 01, 2018, 06:22:14 PM »

Nope. When I placed it exactly how you said all it did was post the you are a bot part at the top of the page. No widget or error.

What have you tried? Where have you tried it? Or are you wanting us to give you an exact answer so you don't learn?
Logged

Sunday
Codemeister
****
Offline Offline

Posts: 395


So meme'd up.


View Profile
« Reply #28 on: April 01, 2018, 06:32:00 PM »

Nope. When I placed it exactly how you said all it did was post the you are a bot part at the top of the page. No widget or error.

What have you tried? Where have you tried it? Or are you wanting us to give you an exact answer so you don't learn?

She tried pasting the code example from TGTarheel between lines 95 and 96 of her modified default petition page.
Logged

Slowly progressing fork with PHP 7 support: https://github.com/stephenKise/Legend-of-the-Green-Dragon
Cheap VPS Hosting (10$ credit!): https://m.do.co/c/acde75b086c5
TGTarheel
Codemeister
****
Offline Offline

Posts: 450


View Profile
« Reply #29 on: April 02, 2018, 01:10:01 AM »

The fact that the code threw no errors is a good start, but since it is obviously not having the desired effect...it means, either it is not in the correct place...or a variable is not setting correctly, causing it to fail before it gives you a chance to pass.

I do not know a lot about this...never have actually worked with CAPTCHA.  I just grabbed the code example that was on the page Nightborn referenced...took out a few variable lines at the top of it...which are already called for elsewhere in the module...and then tried to figure the logical place to put it...and then worked with the parsing of the curly brackets.

It might be helpful to see a module that incorporates the old CAPTCHA....to see what it actually does....and work from that point.  I dunno...I admit I am sorta the blind leading the blind on this...
Logged
Pages: 1 [2] 3   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Play LoGD on Dragonprime

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Recent Topics
DragonPrime LoGD
Who's Online
52 Guests, 0 Users
Home Forums News Downloads Login Register Advanced Search