F.A.Q.


This FAQ contains some of the more common issues that are encountered when trying to configure Securimage. Please post a question if your problem is not addressed here or feel free to use the contact form to ask your question directly.

Some of the problems that are encountered may require some basic PHP knowledge in order to troubleshoot and solve therefore some of these answers may be geared towards more advanced users. If you cannot easily get Securimage working it may be necessary to get help from a skilled PHP developer.

 
If this error appears it means PHP does not have GD support which is required for creating images with PHP. Unfortunately, if you get this error Securimage will not work.

GD has been included with PHP since version 4.3 but some older PHP installations do not support it. You will need to contact your webhost to request GD support, or recompile PHP with GD support if you are running Securimage on your own server.

See the Installing/Configuring GD page on php.net for more information.
This problem may indicate that your version of PHP does not have GD support as indicated in the previous FAQ question but it is possible that Securimage will still work. Depending on your PHP and GD versions this function may not be defined.

To have Securimage use the regular imagecreate() function a background image must not be used and transparent text needs to be turned off. Under these two conditions the imagecreate() function will be used.

Note: This function will not work with GIF images. It is recommended to use the PNG format for your images.
Your version of PHP does not have FreeType support built in. FreeType must be installed in order to use TTF fonts.

You can still use Securimage but you will need to use GD fonts instead of TTF fonts. It is advised to use TTF fonts if possible as certain features of Securimage will not work when using GD fonts (i.e. multiple letter colors, image distortion, transparent text, angled text). GD fonts are also system dependent and can be difficult to find.
If the code does not appear on the image it usually means one of two things. Either the path to the TTF file is incorrect or there is a problem displaying transparent text in the PHP and GD version you are using.

First see if the text will appear by setting use_transparent_text to false (ex. $img->use_transparent_text = false;).

If the text still does not appear, you will need to make sure the path to the TTF font file is correct and that the font file is accessible. It is recommended to use an absolute path to the TTF file. This varies between configurations and web hosts but some examples are (/home/yoursite/public_html, /var/site/html for Unix/Linux or C:\inetpub\wwwroot on Windows). If you are unsure of the path, check with your host or try the following code: $img->ttf_file = $_SERVER['DOCUMENT_ROOT'] . '/securimage/font.ttf'; The font name and Securimage folder will depend on where it was uploaded and what font is uploaded.
Make sure that the URL specified in the HTML img tag points to the proper location of securimage_show.php. To be sure you can use the full address (i.e. http://yoursite.com/securimage/securimage_show.php).

To verify that another problem doesn't exist, try viewing the image directly in your browser by going to securimage_show.php in your browser.
A fatal PHP error may have occurred that is preventing the image from displaying and the PHP configuration is not set to show error messages. To enable error display add the following code just after <?php in your securimage_show.php script: ini_set('display_errors', 'on'); error_reporting(E_ALL);

After saving the file with those changes go to securimage_show.php in your browser to see if any errors are displayed that can help in determining why the image is not showing.
This means that the path to securimage passed to the include statement was not found. You will need to change the include "securimage.php"; line to point to the correct location. The paths vary between servers and configurations but this is the absolute path to securimage.php. In 99.9% of scenarios using include "/securimage/securimage.php"; is incorrect.

If you are unsure of your path, contact your host or try changing the include to include $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';.
Securimage depends on PHP sessions to store the CAPTCHA code in between requests to the server. Because most sessions use cookies, a header must be sent to the user's browser and headers MUST be sent before any portion of the page content is displayed.

Securimage will attempt to attach itself to an existing session but will attempt to create a new one if one does not exist. Because of this, your code must have a session established or securimage.php must be included before any HTML is sent. The easiest way to solve this is to start a session at the very beginning of the first page that is named in the error message (page.php as shown above). To do this use <?php session_start(); ?> on line 1 of the page.

If you are integrating securimage.php into an existing software platform you should make sure starting a session yourself will not interfere with its operation.
This may be due to a problem with the PHP session that is used to keep track of the user and what their code is. It is possible that the session was not started or more likely that the session name being used in securimage_show.php differs from the session name used in the script that does the code validation. It is common for other software platforms (forums, content management systems, form processors etc.) to use a session name other than the PHP default. If this is the case, you must determine what session name is used by the software and use the same session name in securimage_show.php and securimage_play.php.

A non-default session name can be passed to Securimage so it can share a session with another software platform with the following code: $img->session_name = 'your_session_name';

Note: Securimage will NEVER destroy a session so it is safe to use with systems that persist user data with sessions; it only changes its own session variables.

  1. 32 Responses to "F.A.Q."

  2. hi, we had made a spanish translation available here , wich you linked at documentation section.
    in case you lost old site content i resend you the link.
    http://www.micromediaargentina.com.ar/bonus/web/php/captcha-validar-formularios/usando-un-captcha-foto-rotativa-aleatoria.php

    cheers.

    By matiasn on Aug 1, 2008

  3. Fantastic script – thanks very much.

    By Luke on Sep 1, 2009

  4. Hi,

    Great script. Though some of our users complained that CAPTCHA shows error "The code you entered was incorrect. Go back and try again." Even though the code is correct.

    Any suggestion?

    By Gaurav on Nov 21, 2009

  5. Since PHP sessions use cookies to track the user, if they have cookies disabled it will always result in an incorrect code. The only other option is to turn off transparent sessions with the configuration setting 'use_trans_sid' but this is considered a security risk. You can also note on the form that the user must have cookies enabled.

    By Drew on Nov 22, 2009

  6. I am test CAPTCHA Secureimage on my zencart site,
    and I am getting the "incorrect code" error.

    I saw the code fix above, and I just need to know where to put the following line of code:

    $img->session_name = 'your_session_name';

    I found my session name (zenid), but where do I put the above code??

    Thanks!

    By Reed on Nov 23, 2009

  7. Hello Drew,

    You are right ! I sent this solution to our customers. Let me wait for the answer.

    I was concerned about this because I was able to login easily, but some of the users can't.

    Thanks. Appreciate your help. I will get back with customers answer :)

    By Gaurav on Nov 23, 2009

  8. You can put it in securimage_show.php right before $img->show();

    By Drew on Nov 24, 2009

  9. Hi – everything seems to be installed correctly, but I can still hit send without entering the code and the mail still goes through. Below my PHP code:

    "smtp.imaginet.co.za",
    "auth" => true,
    "username" => "Mail@theleatts.co.za",
    "password" => "#######"
    );

    $mail = Mail::factory("smtp", $paramsSMTP);

    $recipient = "#######";
    $headers['From'] = $_POST['Email'];
    $headers['To'] = "#######";
    $headers['Subject'] = 'Website Feedback – http://www.posthouse.co.za – ' . $_POST['name'] . " " . $_POST['surname'];
    $body = $_POST['Body'];
    $mail->send($recipient, $headers, $body);

    if ($securimage->check($_POST['captcha_code']) == false) {
    // the code was incorrect
    // handle the error accordingly with your other error checking

    // or you can do something really basic like this
    die('The code you entered was incorrect. Go back and try again.');
    }

    ?>

    Please help!

    By JP Greeff on Nov 24, 2009

  10. The reason is because the code validation is done after the email is already sent. You want to check the code along with the other form validation before the email is sent.

    The way it is now no matter what code they enter it doesn't get checked until all of your processing is already done.

    By Drew on Nov 24, 2009

  11. Hi Drew – Thanx for the quick reply. I'm VERY new to PHP. The mail form is code that was provided to me by the host. Where do I add this code then?

    By JP Greeff on Nov 24, 2009

  12. There may be a better place to put it but as you said since the php tags were getting cut off you could put it just above the code you had posted. This way if the code is incorrect it will cause the script to stop just before the mail is actually sent.

    Usually, I recommend checking the code after all other form validation and only checking it if there were no other errors with the form input.

    By Drew on Nov 24, 2009

  13. Thanx Drew: Code Follows: Without the PHP Bits at beginning and end:

    include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
    $securimage = new Securimage();

    if ($securimage->check($_POST['captcha_code']) == false) {
    // the code was incorrect
    // handle the error accordingly with your other error checking

    // or you can do something really basic like this
    die('The code you entered was incorrect. Go back and try again.');
    }

    require_once("Mail.php");

    $paramsSMTP = array(
    "host" => "smtp.imaginet.co.za",
    "auth" => true,
    "username" => "Mail@theleatts.co.za",
    "password" => "######"
    );

    $mail = Mail::factory("smtp", $paramsSMTP);

    $recipient = "######";
    $headers['From'] = $_POST['Email'];
    $headers['To'] = "#####";
    $headers['Subject'] = 'Website Feedback – http://www.#####.co.za – ' . $_POST['name'] . " " . $_POST['surname'];
    $body = $_POST['Body'];
    $mail->send($recipient, $headers, $body);

    By JP Greeff on Nov 24, 2009

  14. Hello Drew. I have been using your Securimage product for a couple of days now. I seem to have everything coded and working on my test machine. When the correct letters and numbers are entered, it works. When I click on the audio link, the letters and numbers that are recited are the correct letters and numbers.

    I recently moved my changed pages along with the supporting files and folders to my production Webhosting company's server. When I pull up the page, I see the Captcha image along with the reload and sound images. The reload image works.

    The sound image, when clicked, recites "other" letters and numbers – not the ones that are displayed in my Captcha box.

    Also, when I type in the letters and numbers that are displayed in my Captcha box, I get a "failure" message – as if the letters and numbers were typed incorrectly.

    I added the Session_Name to my files (as you noted above) and assuming I did all of it correctly, it didn't help my problem – I still can't seem to get this thing to work on my production server.

    My test server is running PHP 5.1 (Captcha works)
    My production server is running 4.4.8 (Captcha doesn't work)

    Can you think of anything else I should try?

    Thank you very much!
    Jesse

    By Jesse on Nov 25, 2009

  15. Hi Drew, many thanks for you script – exacly what I was after.

    The only problem is that it only validates if all of the characters are entered in lowercase, even the ones that are show as upper case in the image. Is there a way to make it so that characters have to be entered in the case shown?

    Many Thanks
    Izzy

    By Izzy on Dec 10, 2009

  16. Currently the script is not case-sensitive as many users do not enter codes case sensitively without going through one incorrect entry.

    Without making a few modifications to the saving and checking of the code it is not possible to do this – perhaps it will be an option in a future version. Sorry.

    By Drew on Dec 10, 2009

  17. Hi,
    I had a problem with short captcha-word in little captcha-box displaying in IE7. I was need to display captcha 84px:25px with 6-letters inside. Image was not redrowing on page refrash. During the tests I had found that some size modifications (heigth to 400px or width to 800px) makes the captcha to be displayed correctly – with 6-letters word inside, otherwise it was displayed with some old long text in some old sizes.
    So, I deside that the real problem is that little size image don't wont to be displayed because of some big image size images caching. So, i had look tou the code you use for cache disabling -
    header("Expires: Sun, 1 Jan 2000 12:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
    etc.
    I have change it to some other code I have use in my previouse projects – and problem is fixed now: any size images are displayed correctly after refresh.
    So, code I propose you is:
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Expires: " . date("r"));
    That's all. I can give you some sources about why this code is correct – but all of them are in Russian, for example this:
    http://nomagic.ru/all.php?aid=58

    By Serge on Dec 14, 2009

  18. I am using forms in a Yahoo store and your anti spam tool was working fine until last week.
    Not anymore…

    I got an error message even if I type the correct code, Securimage always says it is wrong…

    I saw in the FAQ to ad code for session.

    I added this in securimage to get the software session name:

    $km_session_name=session_name();
    session_start();

    and I added this one in both show and play:
    $img->session_name = $km_session_name;

    What I echo on the error page, it shows $km_session_name is null.
    is there another way for me to get the curent session name?

    I am not sure I understand what else can I do???

    Thanks for your help, in adavnce!!

    Ka

    By Ka on Dec 15, 2009

  19. Hi when I run the following code as validation, the php script doesn't work.
    Why would this be?
    (securimage 1.0.1.3)

    … some more php code
    if (($captcha_code == "")) {
    exit;
    }

    // check captcha code
    session_start();
    include("/securimage/securimage.php");
    $img = new Securimage(); //check($_POST['captcha_code']);
    if($valid == false) {
    exit;
    }
    … some more php code

    By Bart Mertens on Dec 22, 2009

  20. hi, and thx for the script.
    is there any way to ad a LINK to the captcha image ?

    By miguel on Dec 24, 2009

  21. hi, I want try to create a new series of audio files (wav and mp3) in italian language. I have create new series of wav files (11025Hz) and mp3 files (16KHz) but, after the substitution, the captha player read only the first letter (or number). I use Audacity for the audio files creation. What is the correct type of the files, for correctly run? thanks

    By ettore on Jan 1, 2010

  22. This is really nice, easy to setup and robust piece of software. Really appreciate the effort. I have a question though.
    Is there a way to setup multiple instances of securimage on same page and then verify the code entered for that particular instance? I was able to create multiple instances on one page but the code verification only works for the last created instance.

    Can someone please tell me if its even possible? or any workaround to get it done? Thanks.

    PS. I posted this question earlier on the Quick Start Guide page but I think this is more appropriate. You can delete the comment from there. Sorry for the inconvenience.

    By Waqas on Jan 5, 2010

  23. It didn't work for me at first; it rejected every submission whether it was correct or not. For some reason, $_SESSION['securimage_code_value'] wasn't being set.

    Eventually, I managed to fix this problem by changing the form action attribute from an absolute to a relative URL.

    Hope this helps someone.

    By Michael on Jan 5, 2010

  24. Ditto, to Michael's post. When form and process pages are in same directory, use relative URL. If in different directories, use absolute. Weird but it worked for me.

    By Stephen on Jan 13, 2010

  25. hi
    i have several questions:
    1- i try to change the number of letters .
    i tried:
    $image = new $securimage();
    $image->code_length = '3′;
    but it does not work.
    the same with image size and others (like number of lines).

    2- can i uae securimage on any site? are there restrictions?
    best regards

    By ron on Feb 8, 2010

  26. Hello,

    I like to use 2 captcha's at the same time in 2 different forms (in 2 browser tabs).
    When i check the registered Session captcha code i see only 1 code "securimage_code_value = lhcd" for the first form. When i request an other form with an other captcha image2, i will see a new registered session-var "securimage_code_value = ke7y".
    When i tab back to the first form, the captcha code is not valid anymore, because the 2nd form has registered a new captcha code and overwrite the session-var "securimage_code_value".

    I think i need 2 registered session-vars (for each form-captcha an own registered captcha-code) like:
    securimage_code1_value
    securimage_code2_value

    Can you tell me this is possible? And how?

    Regards,
    Guido

    By Guido Lemmens on Feb 11, 2010

  27. Is there a way to change the size of the font? I am using the TTF font that came with the securimage download. However, I find that if I reduce the size of the image via, $img->image_width, to lower than ~230, letters on the right hand side 'falls off' the edge of the image. This should be obvious but I can't find the setting.

    By George on Feb 11, 2010

  28. Great script. How would i implement radio buttons. I have used checkboxes no problem.

    Thank You

    By John on Feb 12, 2010

  29. I get the following error after submitting my form to my validation script:

    Warning: Failed to load GD Font file gdfonts/automatic.gdf in C:\xampp\htdocs\securimage\securimage.php on line 844

    Any ideas how to resolve this?

    By rajend3 on Feb 18, 2010

  30. Just a little information for evrybody…

    If you make you .mp3 files don't foget to remove the IDTAG because it's a problem for the stream whith the flash player and you have only the 1 word.

    By fredlynx on Feb 22, 2010

  31. HELP PLEASE!! First, it seemed to work and would send the message but pull up a weird error message. I reloaded the php pages and now the Script seems to run as if it's working but it's not sending that actual eMail?? I assigned the email address in the process.php page.. Very confused. Any advice would be greatly appreciated.

    By Firefighter Po on Feb 23, 2010

  32. Our captcha works fine with internet explorer…however with Firefox we receive an "invalid captcha code entered" every time, even though we enter the correct code. Can anyone think of what the difference might be? Firefox 3.5.8

    Thanks!

    By Tom C on Mar 7, 2010

  33. i setup this captcha for a joomla component but it seem joomla does not understand the session in file securimage.php and the result is always incorrect ? you have any recommend ?

    By rikka on Mar 10, 2010

Post a Question

CAPTCHA Image
Reload Image
Enter Code Below