Using hCaptcha with PHP

Want to integrate hCaptcha on a site with PHP? It only takes a few seconds.

Step 1: Sign up on

You’ll need your “site key” and “secret” in order to proceed.

Step 2: Add hCaptcha to your site HTML.

A. Add the JavaScript library to your page, for example in the <HEAD> or <BODY> block.

B. Add this HTML code where you want to show the hCaptcha button, for example inside a login form. Remember to replace “your_site_key” with your actual site key!

Step 3: Validate the result on your backend server.

In order to confirm the user sent you a real passcode, and in order to get credited for the answer, you must check the result from your server while providing your secret.

The simplest way to do this with PHP is something like the following. Remember to replace “your_secret_key” with your actual secret!

if you prefer the cURL style, you could use:

We do not suggest using a GET request with URL parameters, like this:

As this may break now or in the future due to the length of the URL.

.. and you’re done!


Q: How do I know if it’s working?

A: You’ll see both the “served” and “solved” counters on your dashboard go up.

If you don’t see “solved” going up after you solve a hCaptcha and check it on the backend, you are not sending siteverify correctly.

Q: How do I prevent the user from submitting a form to my server without a valid hCaptcha response?

Q: What does a complete PHP contact form example look like?

A: here’s a complete example. Put this in contact-form.php and add your secret and site key.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store