Categories > Coding > PHP >

[I NEED HELP] SPENT 3 DAYS TRYING TO MAKE HCAPTCHA WORK

TERIHAX

i say im gay as a joke 🙀

Posts: 2195

Threads: 102

Joined: Jul, 2020

Reputation: 30

Posted

HELP I SPENT 3 DAYS TRYING TO MAKE HCAPTCHA WORK, BUT ITS NOT WORKING

 

BASICALLY I WANTED TO MAKE HCAPTCHA WORK FOR A SITE AND I EXPECTED IT TO BE VERY QUICK, BUT SINCE I HAVE 0 KNOWLEDGE ON PHP AND I MADE SOMETHING REALLY QUICKLY, IT DIDNT WORK

 

im not planning to be some sort of big php dev, i just want to finish this and never touch it again and go back to learning cpp and try out the sht ethan was doing

 

php code:

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Validate and sanitize the hCaptcha response
    $response = filter_input(INPUT_POST, 'h-captcha-response', FILTER_SANITIZE_STRING);
    if ($response === null || $response === false) {
        echo "Invalid hCaptcha response";
        exit;
    }


    // Verify the hCaptcha response
    $data = array(
        'secret' => "i removed my secret key obv but im sure its right",
        'response' => $response
    );

    $verify = curl_init();
    curl_setopt($verify, CURLOPT_URL, "https://hcaptcha.com/siteverify");
    curl_setopt($verify, CURLOPT_POST, true);
    curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($verify);
    curl_close($verify);

    $responseData = json_decode($response);

    if ($responseData && $responseData->success) {
        header("Location: https://google.com");
        exit;
    } else {
        echo "Captcha verification failed";
        exit;
    }
}

 

and my JS code:

function checkCaptcha()
    {
        hcaptcha.execute('MY SITE KEY AND IM SURE IT WORKS', { action: 'verification' })
            .then(function(token) {
                $.ajax({
                    url: window.location.href,
                    method: 'POST',
                    data: { 'h-captcha-response': token },
                    success: function(response) {
                        console.log(response);
                    },
                    error: function() {
                        console.error('Error during captcha verification');
                    }
                });
            })
            .catch(function(error) {
                console.error('Captcha execution error:', error);
            });
    }

 

the JS code is inside the <script></script> tags in the php file.

 

HTML:

<form method="POST">
            <div class="h-captcha" data-sitekey="MY SITE KEY REMOVED BUT IM SURE ITS RIGHT" data-theme="dark"></div>
        </form>
        <button id="continue-btn" onclick="checkCaptcha()">Continue</button>

 

basically when i finish the captcha, and i press the continue button, i get this error in the console:

https://i.gyazo.com/0704dc248847637000d346fbdb479a55.png

 

im 100% sure the site key and the private key is right, and i really dont know why its not working properly

  • 0

Posts: 1395

Threads: 71

Joined: May, 2022

Reputation: 17

Replied

this is what you get for using php :troll:

Comments

TERIHAX 30 Reputation

Commented

yea but idrk what else to use for this

  • 0

  • 0

Did I mention I use arch btw?

RiceUsesArchBtw

rice cracker

vip

Posts: 455

Threads: 19

Joined: Aug, 2021

Reputation: 38

Replied

well dont use php

Comments

Whoman 17 Reputation

Commented

the only correct answer

  • 0

Goldberg 2 Reputation

Commented

please comment useful comments, guy needs help with coding not useless comments that doesnt solve the problem, he doesnt want to switch from php he wants help

  • 3

  • 0

https://cdn.discordapp.com/attachments/1023423265160560745/1132948683747500092/Frame_12x.png

Murz

PixelPenguin

Posts: 239

Threads: 20

Joined: Jul, 2021

Reputation: 28

Replied

Sorry for all the responses that aren't so helpful, here is what I found on a quick search;

 

Have you tried putting ```<script src='https://www.hCaptcha.com/1/api.js' async defer></script>``` inside of the HEAD or BODY area?

Comments

TERIHAX 30 Reputation

Commented

yes i have, but that link is outdated, theres a newer one.

i have htis in the HEAD

<script src="https://js.hcaptcha.com/1/api.js" async defer></script>
  • 0

Murz 28 Reputation

Commented

@TERIHAX, sorry I do not know what else to do to help you then. I assume three more assumptions.

 

1) Your key is wrong.

2) Improper tags (i.e "theme")

3) The API is the problem.

 

However, fear not I do have a website you can look at!

https://medium.com/@hCaptcha/using-hcaptcha-with-php-fc31884aa9ea

 

Goodluck, Teri!

  • 0

TERIHAX 30 Reputation

Commented

@Murz ive followed that b4, and the tags are all right, same problem

  • 1

  • 0

 

Ty for rep: Swiney, Byoke, Lion, Locust, Waves, Weeb, Nickk, darkn, Atari, CubeFaces, Lux14, Rice, Delta, Syraxes, Aeon, Jordan, Pluto, and Hiroku!

P.S, I like cats better too!

Posts: 1002

Threads: 66

Joined: Sep, 2021

Reputation: 20

Replied

php sucks, use node js. it faster, and newer.

Comments

TERIHAX 30 Reputation

Commented

people can disable javascript and i dont wnat that happening

  • 0

crazy_cat 20 Reputation

Commented

@TERIHAX node js is a server-side enviroment, and has nothing to do with the browser. it will continue to work, whether js is enabled, or not.

  • 0

TERIHAX 30 Reputation

Commented

@crazy_cat ohh i see

  • 0

  • 0

"Building blocks of imagination, united in the virtual realm, where creativity thrives and friendships ignite. Welcome to the Roblox revolution!" - chatgpt

 

Posts: 1

Threads: 0

Joined: Jun, 2023

Reputation: 0

Replied

Don't use php.

my location

  • 0

SkieHackerYT

Panda Development Team

vip

Posts: 367

Threads: 88

Joined: Apr, 2019

Reputation: 31

Replied

Have you heard abt ChatGPT (sound dumb but heck you can fix it if you may follow's the instrucion of chatgpt)

Comments

TERIHAX 30 Reputation

Commented

no it doesnt work

  • 0

linemaster 0 Reputation

Commented

ChatGPT is retarded for stuff like that

  • 0

TERIHAX 30 Reputation

Commented

@linemaster, no it sometimes works well but breaks from time to time

  • 0

  • 0

https://media.discordapp.net/attachments/996322272547704845/1016492646820233246/standard.gif

https://cdn.discordapp.com/attachments/1074291934501290087/1085354909609754775/PelicanDevelopment.gif

Posts: 2

Threads: 0

Joined: Jun, 2023

Reputation: 0

Replied

I have the same concern. 

backrooms

  • 0

Posts: 1

Threads: 0

Joined: Jun, 2023

Reputation: 0

Replied

It can be frustrating when you encounter unexpected challenges while working on a project, especially when you're navigating unfamiliar territory like PHP. It's understandable that you wanted to quickly implement a captcha on your site, but sometimes lack of knowledge can hinder progress. It's great that you made an effort to tackle it swiftly, even though it didn't work out as expected. Remember, codes are a continuous learning process, and we all encounter hurdles along the way. Once you overcome this hurdle and finish the task, you can shift your focus back to learning C++ and exploring the fascinating things Ethan was doing. Keep pushing forward, and don't let temporary setbacks discourage you from your coding journey!

  • 1

Users viewing this thread:

( Members: 0, Guests: 2, Total: 2 )