After enabling the module, at the comment submission form:

Fatal error: Cannot use string offset as an array in captcha.module on line 416

CommentFileSizeAuthor
#21 fatalerror_stringoffset_asarray.patch880 bytessoxofaan
#20 captcha_debug.txt4.05 KBAnonymous (not verified)

Comments

archetwist’s picture

Forgot to write that I use PHP 5.

soxofaan’s picture

Can you give more (step by step) info to reproduce the bug?
I can't reproduce it (with PHP 5.1.6, Apache 2, Drupal 5.2, captcha HEAD)

spyderpie’s picture

I have the same error. PHP5, Apache2, Drupal 5.2.

Except mine says line 257.

I enabled the captcha and image captcha modules. (Not text captcha) and then set the config as follows: (Forgive me I don't remember exactly the wording ... and can't get back there)

I checked the box to use captcha on forms and selected the register and password forms. I unselected the persistent captcha box, saved and went to the image captcha form. There i told it to use the text image captcha option. When i logged out and then selected 'forgot my password', I saw the image with the word 'dirt' in it. Then i hit refresh to see it change and this is where the error appeared.

I then logged in as administrator and now the site it completed unavailable. Everything I click gives that error. Even if I manually type /admin/settings in the url.

Thank goodness i tested it on a test site ... but if I didn't I would be in a 'site down' mode :)

Julie

spyderpie’s picture

An update:

Line 257 in the actual captcha.module has nothing to do with it .. I know cause I rem'd it out and nothing happened.

The good news is that if you go into the system table, and disable all three captcha modules, captcha, text captcha and image captcha - you will be able to get back into the site.

I went back to admin/build/modules and activated all three this time, then configured it to use image_captcha -- all other settings the same ... all is well ...

Could it be because I had not enabled the text captcha but told it to use textimage?

Julie

soxofaan’s picture

@spyderpie

Could it be because I had not enabled the text captcha but told it to use textimage?

Do you mean with 'textimage' the textimage module at http://drupal.org/project/textimage ?
The text captcha submodule (included with the captcha module tarball) has nothing to do with textimage stuff.

So if I understand you correctly you use captcha-5.x-3.0-rc1 + the textimage module (version 5.x-1.2?). Textimage is not guaranteed to work with the new reworked core captcha module whatsoever because the captcha API changed.

spyderpie’s picture

wooooooooooooooooooow

interesting.

I have just disabled the text image module, since I don't need it. Amazing how you forget as you build over time, what you put there and why! LOL

1 less module is always good!

Anyways, i wonder if that is the same problem that archetwist had ... ??

Thanks for being responsive and patience of course.

Julie

robloach’s picture

Does this problem still persist?

robloach’s picture

Status: Active » Closed (fixed)

Closing the issue as no one has reported it.

Anonymous’s picture

Version: 5.x-3.0-rc1 » 5.x-3.0-rc3
Status: Closed (fixed) » Active

Unfortunately, too early to close - I have to report this problem with the latest rc3. When enabled, captcha will invariably display the same error :

Fatal error: Cannot use string offset as an array in /path/to/drupal/sites/all/modules/captcha/captcha.module on line 311

... but only when visitors are coming with the Konqueror web browser! I have tried with firefox on same conditions (i.e. not logged in) and it works without any problem. If the module is uninstalled, Konqueror users have no problem coming to my page.

Very weird.

robloach’s picture

Status: Active » Postponed (maintainer needs more info)

Do you experience this with 5.x-3.x-dev? What code is at line 311 of captcha.module?

soxofaan’s picture

line 311 of captcha.module from DRUPAL-5--3-0-rc3 reads:

    if(!variable_get('captcha_persistence', TRUE) && ($_SESSION['captcha'][$form_id]['success'] === TRUE)) {

My guess: Gnurou using PHP4 and cookies are disabled in konqueror. is this correct?

If I disable cookies in konqueror and try to submit a CAPTCHA enabled form I get:

* Invalid captcha token.
* The answer you entered for the captcha challenge was not correct.

but that's with PHP 5.1.6

robloach’s picture

Think we should provide a better descriptions then "Invalid captcha token."?

Anonymous’s picture

Actually I'm using PHP5 and cookies were enabled. But the weird thing is that I tried on another machine (still using Konqueror) and it works flawlessly. I'll try again with the -dev version.

The weirdest thing being that actually the page that triggers the error is the home page, which does not display any catcha. I think others page would not work neither, I'll try to confirm this once I return to the faulty Konqueror instance.

soxofaan’s picture

Think we should provide a better descriptions then "Invalid captcha token."?

It is indeed a bit cryptic.
Some causes for the error I can think of right now:

  • CAPTCHA API mismatch
  • user tries to post the same form two times
  • user tries to post form_values without requesting the form first (typically for spam bots I guess)
  • cookies are disabled

What about: "Unable to retrieve your CAPTCHA data."?
or "Unable to retrieve your CAPTCHA data. Possible causes: cookies are disabled, you tried to re-post the form, CAPTCHA API mismatch."?

Anonymous’s picture

Using 5.x-3.x-dev, the error still appears, this time only when I load pages where captcha appears:

Fatal error: Cannot use string offset as an array in
/path/to/drupal/sites/all/modules/captcha/captcha.module on line
583

Line 583 reads:

$_SESSION['captcha'][$form_id][$captcha_token] = $form['captcha']['captcha_solution']['#value'];

Strange thing is that, once again, this problem only appears on ONE instance of Konqueror (that I use home). On another machine, even though the same distro, same version is installed (Kubuntu Feisty), I don't have this problem. I really don't understand how this can be.

soxofaan’s picture

Weird indeed.
Can you give more information on:
* the versions of PHP, Apache, Konqueror, Drupal, ...?
* your website setup: shared host, running on localhost, working with proxies?
* which CAPTCHA type do you use?
* did you try other CAPTCHA types?
* what other possibly relevant modules are enabled?

soxofaan’s picture

at #15:

can you put

  header('Content-Type: text/plain');
  var_dump($form_id);
  var_dump($captcha_token);
  var_dump($_SESSION);
  var_dump($form['captcha']);

before that line 583 and post the stuff it spits out? (use text attachement)

I've googled for the error and found following interesting information:
http://www.zend.com/forums/index.php?t=msg&goto=6396#msg_num_4
http://bugs.php.net/bug.php?id=32621

robloach’s picture

If you have the Devel module installed, you can use:

drupal_set_message(dprint_r($form_id, TRUE));
drupal_set_message(dprint_r($captcha_token, TRUE));
drupal_set_message(dprint_r($_SESSION, TRUE));
drupal_set_message(dprint_r($form['captcha'], TRUE));

I've found that very handy for debugging.

soxofaan’s picture

at #18:
the devel module provides a even shorter way to do that:

dvm($form_id);
dvm($captcha_token);
dvm($_SESSION);
dvm($form['captcha']);

very handy indeed (I use it all the time).
But I assumed that Gnurou did not have the devel module installed, so I thought the var_dump() trick would be the easiest way to get that data.

Anonymous’s picture

StatusFileSize
new4.05 KB

Here is the requested information:

My server runs Ubuntu Feisty
* PHP is 5.2.1
* Apache is 2.2.3
* Drupal is 5.2
* Konqueror is 3.5.6

The server is a virtual dedicated (User Mode Linux), the drupal instance is used by several websites. I've only been activating the base Captcha module and using the base Captcha (i.e. Math problem). I have translated a couple of strings to French because that's the language my users are speaking (which makes me think, I should finish the job and submit a po sometime).

Here is the log I get when adding the requested lines. Indeed, my server being in production, I don't have the devel module installed. ;)

Hope this helps!

soxofaan’s picture

Status: Postponed (maintainer needs more info) » Active
StatusFileSize
new880 bytes

Thanks for that debug info, that really helps

It seems you used an other/older CAPTCHA version before. Is that correct? The session variable $_SESSION of your konqueror user is:

array(2) {
  ["captcha_correct"]=>
  bool(false)
  ["captcha"]=>
  string(1) "5"
}

First: the key "captcha_correct" in this array is not used/generated by the CAPTCHA base module v5.x-3.x.
Second: the key "captcha" should point to a nested array and not a string ("5" here), this is the source of the message "Fatal error: Cannot use string offset as an array in captcha.module".
Another very weird thing is that $captcha_token is NULL, while $form['captcha']['captcha_token']['#value'] is "03ecfa6e23d5d93c145aa1c669329fc2"

The things you can do (one of them should be enough):

  • Server side: clear the session variable of that user (an maybe other users), you can do that e.g. by flushing the session table (e.g. with phpmyadmin if you know how to do that) or at least deleting the problematic sessions (if you can find these)
  • Client side: maybe clearing the right cookies in konqueror may also work
  • patch captcha.module (dev version) with attached patch as experiment (I don't think this patch should make it to the official version, though)
wundo’s picture

#21,
If we force to clean cache in .install should fix it, don`t ?

soxofaan’s picture

at #22:
no, it has nothing to do with caching, it is a session thing.
And cleaning all the sessions in .install seems a bad idea because everybody will be logged out (including user 1)

Anonymous’s picture

Soxofaan, thank you very much. I've cleared the cookies for my domain in Konqie and things worked as they should. So as this is not a Konqueror-specific problem, I've cleared my sessions tables to make sure no other user run into these problems, and reactivated Captchas with peace of mind. ;)

I think this bug can safely be closed now.

robloach’s picture

Status: Active » Fixed

Excellent! Be sure to get the 5.x-3.x-dev version too, it has a bunch of new updates.... Very very close to 3.0 final now.

greggles’s picture

Title: Cannot use string offset as an array » Cannot use string offset as an array in captcha.module

This seems to be an irregular bug. On a multisite of mine I had 3 sites using captcha. I upgraded 2 of them and it worked fine, but the third one exhibited this problem.

I agree that clearing sessions seems like an unnecessarily harsh solution, but I think something should be possible.

If the solution isn't in code then at least a warning message seems useful.

Also, changing title to more accurately reflect the error message to help people find this issue.

Anonymous’s picture

Status: Fixed » Closed (fixed)