jack778 has asked for the wisdom of the Perl Monks concerning the following question:

I tried to use the Perl Module Captcha::reCAPTCHA::V2 to verify Google's reCAPTCHA widget but encountered problems.

I installed the module in the server. To ensure it works, I've written a test script as follows:

#!/usr/bin/perl use Captcha::reCAPTCHA::V2; print "Content-type: text/html\n\n"; print "Hello World<br>\n"; exit;
Ran the script but it returned "Internal Server Error" in the browser. The server log files indicates the problem is due to "End of script output before headers".

If I do this in the script:

#!/usr/bin/perl #use Captcha::reCAPTCHA::V2; print "Content-type: text/html\n\n"; print "Hello World<br>\n"; exit;
it works.

So the "End of script output before headers" error has to do with Captcha::reCAPTCHA::V2.

Could you kindly advise how to use Captcha::reCAPTCHA::V2?

Thanks,

Jack

Replies are listed 'Best First'.
Re: Captcha::reCAPTCHA::V2 Not Working
by Corion (Patriarch) on Jan 10, 2019 at 14:53 UTC

    The first step is to look deeper into the web server error log. Maybe the module is not installed at all, or not accessible to the user your CGI script runs as?

      The module is installed.

      The server log says error is due to "End of script output before headers".

Re: Captcha::reCAPTCHA::V2 Not Working
by 1nickt (Canon) on Jan 10, 2019 at 14:50 UTC

    Hi, your original code works for me:

    $ perl 1228317.pl Content-type: text/html Hello World<br>

    Hope this helps!


    The way forward always starts with a minimal test.

      My script works if it runs in Secure Shell (SSH)

      But it does not work with web browser.

      Weird.
Re: Captcha::reCAPTCHA::V2 Not Working
by holli (Abbot) on Jan 10, 2019 at 18:42 UTC
    Don't nail me on that, but iirc
    End of script output before headers
    means that there is output written to STDOUT before the http-headers are written thereto. Try printing the headers before using the module. That way you can check the output for something unexpected.


    holli

    You can lead your users to water, but alas, you cannot drown them.
      use is done before any print. If CGI::Carp is available, insert
      use CGI::Carp 'fatalsToBrowser';
      right after she shebang line.

      Update: better:

      use CGI::Carp qw(fatalsToBrowser warningsToBrowser);

      I tried printing the headers before using the module, got the same results, "Internal Server Error" in the browser
      #!/usr/bin/perl print "Content-type: text/html\n\n"; use Captcha::reCAPTCHA::V2; print "Hello World<br>\n"; exit;
      Frustrated!
        Frustrated!

        If you can't talk to your hoster then you need to investigate by yourself. Since use is a comile-time statement any failure in it will happen before your script even tries to run. Instead, go with require and wrap it in an eval block to trap the errors.

        #!/usr/bin/perl use strict; use warnings; print "Content-type: text/plain\n\n"; eval { require CGI::Carp; } or print "CGI::Carp not loaded: $@.\n"; eval { require Captcha::reCAPTCHA::V2; } or print "Captcha::reCAPTCHA::V2 not loaded: $@.\n"; print "End of script\n";

        Also, always check the full entries in the error log, not just the last line.