Categories > Coding > PHP >
[I NEED HELP] SPENT 3 DAYS TRYING TO MAKE HCAPTCHA WORK
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
Cancel
Post
Replied
this is what you get for using php :troll:
Cancel
Post
Did I mention I use arch btw?
Replied
well dont use php
Comments
Cancel
Post
https://cdn.discordapp.com/attachments/1023423265160560745/1132948683747500092/Frame_12x.png
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>
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!
Cancel
Post
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!
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
TERIHAX 30 Reputation
Commented
@crazy_cat ohh i see
Cancel
Post
"Building blocks of imagination, united in the virtual realm, where creativity thrives and friendships ignite. Welcome to the Roblox revolution!" - chatgpt
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
linemaster 0 Reputation
Commented
ChatGPT is retarded for stuff like that
TERIHAX 30 Reputation
Commented
@linemaster, no it sometimes works well but breaks from time to time
Cancel
Post
https://media.discordapp.net/attachments/996322272547704845/1016492646820233246/standard.gif
https://cdn.discordapp.com/attachments/1074291934501290087/1085354909609754775/PelicanDevelopment.gif
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!
Cancel
Post
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Comments
TERIHAX 30 Reputation
Commented
yea but idrk what else to use for this
0