For the life of me, I couldn’t figure out why the Sky Forms CAPTCHA was showing ERROR! on my Unify Theme Bootstrap 3 deployment.
Turns out this was just a rookie mistake… I wasn’t looking closely enough at the “how it works” and I was missing some code from the demo-contacts.php sample file that was crucial to the operation of the CAPTCHA. This code generates the CAPTCHA itself and stores it in SESSION data. Since it was missing, the CAPTCHA system’s image.php was turning out an ERROR!
// Make the page validate ini_set('session.use_trans_sid', '0'); // Create a random string, leaving out 'o' to avoid confusion with '0' $char = strtoupper(substr(str_shuffle('abcdefghjkmnpqrstuvwxyz'), 0, 4)); // Concatenate the random string onto the random numbers // The font 'Anorexia' doesn't have a character for '8', so the numbers will only go up to 7 // '0' is left out to avoid confusion with 'O' $str = rand(1, 7) . rand(1, 7) . $char; // Begin the session session_start(); // Set the session contents $_SESSION['captcha_id'] = $str;
That $_SESSION[‘captcha_id’] is what the image.php file is looking for. If it doesn’t find it, ERROR!
Refresh, and we’re good to go!
-Robbie
Thanks Robbie,
Couldn’t see the wood from the trees, all working fantastically now.
Thanks for your help, have a great day 🙂
Glad I could help, Mark.
For those wondering, Mark had hard-coded an override in php.ini for the session storage directory for the top-level of his site, but since image.php resides in a subfolder (eg., assets/) its session was in the default folder. Therefore, each session_start() was saving in a different place… essentially the user had two sessions. I reset the storage folder for PHP sessions to default storage folder (likely /tmp) and all is well.
Mark I also redid your CAPTCHA random code generation ($char) – see the comment at the top of your index.php for more info.
Just a side note, I also changed the angle of the text of the CAPTCHA image (see image.php) to 5% instead of 10%. The default (10%) can result in the text getting cut off by the edge of the image when the angle of the text is too high, which I’d personally consider a bug and should be fixed in the core.
If you need any more help, you know where to find me. My webcast is also a great resource – http://www.category5.tv
Thanks,
Robbie
Your a STAR Robbie, thanks
Hi Bald Nerd,
I am having this exact trouble and its driving me nuts.
Scenario
-> have this working on my dev server (Session stored in files), captcha displays fine.
-> copied files to hosting company. I have 2 issues.
a) I seem to get 2 session files
b) The image.php doesn’t pick up the session (i have added debug statements)
Therefore I always get ERROR displayed.
I have checked permissions of directories. and files and all looks like a match to my local development server. Any ideas what else I can try.
Many thanks for any help you could offer.
Mark
Hey Mark,
Happy to help. Since part of this code is server-side, it’s tough to diagnose without access to the server in question. If you’d like, zip up the file(s) and email them to me and I’ll take a look and post here. Just your php files pertaining to this issue (eg., I don’t need your whole directory… probably just the one file where the ERROR is being displayed). [email protected]
Thanks for reading.
Robbie (AKA Bald Nerd)