Skip to content

Instantly share code, notes, and snippets.

@robtuley
Last active August 29, 2015 14:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robtuley/11222c4f7aeddf156f81 to your computer and use it in GitHub Desktop.
Save robtuley/11222c4f7aeddf156f81 to your computer and use it in GitHub Desktop.
<?php
session_start();
$url = 'http://api.textcaptcha.com/example.json';
$captcha = json_decode(file_get_contents($url),true);
if (!$captcha) {
$captcha = array( // fallback challenge
'question'=>'Is ice hot or cold?',
'answers'=>array(md5('cold'))
);
// + capture error info & log
}
// display question to user as part of form
echo htmlentities($captcha['question']);
// store answers in session
$_SESSION['captcha_ans'] = $captcha['answers'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment