If this is your first visit, check our documentation. To post, register or login.
Forums / Community Contributed Add-Ons / All Other Contributions/Addons / PHP Warning: addslashes() expects parameter 1 to be string, array given

PHP Warning: addslashes() expects parameter 1 to be string, array given

Started by schoolboy on 5 Jul 2012, 4:25 AM · Views: 12,282

Results 1 to 12 of 12
5 Jul 2012, 4:25 AM
#1
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Post #1 by schoolboy

We're getting quite a few of these on some of our sites:

PHP Warning: addslashes() expects parameter 1 to be string, array given in /home/XXXXXXX/public_html/includes/functions/functions_general.php on line 888

20 years a Zencart User

5 Jul 2012, 4:56 AM
#2
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Post #2 by schoolboy

Interestingly... all are appearing in Cache Logs of sites we have INHERITED - not developed ourselves from scratch.

Likely therefore to be caused by some cranky add-on, so we will look for commonality across sites (which are using the same modules, and getting this warning) and we will also look at server log activity for time stamps.

But if anyone is experiencing the same warning, please let me know if you've nailed down the (probable) cause...

20 years a Zencart User

9 Aug 2012, 10:13 AM
#3
picandnix avatar

picandnix

Totally Zenned

Join Date:
Dec 2010
Location:
UK
Posts:
1,779
Plugin Contributions:
2

Post #3 by picandnix

Any luck with this error yet? I have it too. I think I've tied it down to account creation stage but before payment is made. Are your guilty sites using FEC?

9 Aug 2012, 10:24 AM
#4
picandnix avatar

picandnix

Totally Zenned

Join Date:
Dec 2010
Location:
UK
Posts:
1,779
Plugin Contributions:
2

Post #4 by picandnix

Actually it could be when removing item from cart?

16 Aug 2012, 7:59 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Post #5 by drbyte

schoolboy:

... in /home/XXXXXXX/public_html/includes/functions/functions_general.php on line 888
In v1.3.9, that would be part of the zen_db_input() function call.
And there are more than 100 places in core code (catalog side) that call that function, plus almost certainly dozens more in each addon the site is using.
You'll need to trace down every one of them to determine whether an array is being passed in any of those cases, and why.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

9 May 2013, 1:07 AM
#6
openvista avatar

openvista

New Zenner

Join Date:
Sep 2009
Posts:
23
Plugin Contributions:
0

Post #6 by openvista

This is in reference to Zen Cart 1.5.1 running on PHP 5.3.

I thought I'd pass along a possible solution.

For me, this problem traced back to the add-on Supertracker 1.1 (latest version). The reason I wasn't able to reproduce it initially is that this add-on allows you to exempt select IPs and since mine was exempted it wasn't performing the database insert at checkout success as it was for other visitors. During the final checkout process it passes an array to the zen_db_input() function, which of course just calls addslashes() which will no longer accept arrays under PHP 5.3. So my ad-hoc solution was the following on about line 860 of /includes/functions/functions_general.php:

  function zen_db_input($string) {  
     if (is_string($string)){ // ADDED to eliminate PHP warnings in myDEBUG logs related to input not being strings
       return addslashes($string);
     } else {
       return $string;
     }
  }   

If anyone can think of a better solution or knows of a reason why I should not return an unprocessed string please let me know. As far as I can tell, the only thing that will happen to array content is that it will be written to the db as "Array" which may be more helpful than nothing. This assumes, of course, that the is_string() native PHP function can accurately determine string content and not let through something it shouldn't.

9 May 2013, 1:31 AM
#7
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Post #7 by divavocals

picandnix:

Any luck with this error yet? I have it too. I think I've tied it down to account creation stage but before payment is made. Are your guilty sites using FEC?

This is what I was going to say as well.. I'm just now leaving work and will have to look when I get home, but this sounds an awful lot like a persistent error I was getting on a site I inheirited that was using FEAC..

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

9 May 2013, 2:56 AM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Post #8 by drbyte

It would be much safer to fix the data being passed, since what you've suggested bypasses the sanitizing that was intended, and if the data isn't actually already reliably clean you could be introducing a SQL Injection risk by your change.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

9 May 2013, 6:18 AM
#9
picandnix avatar

picandnix

Totally Zenned

Join Date:
Dec 2010
Location:
UK
Posts:
1,779
Plugin Contributions:
2

Post #9 by picandnix

openvista:

This is in reference to Zen Cart 1.5.1 running on PHP 5.3.

I thought I'd pass along a possible solution.

For me, this problem traced back to the add-on Supertracker 1.1 (latest version). The reason I wasn't able to reproduce it initially is that this add-on allows you to exempt select IPs and since mine was exempted it wasn't performing the database insert at checkout success as it was for other visitors. During the final checkout process it passes an array to the zen_db_input() function, which of course just calls addslashes() which will no longer accept arrays under PHP 5.3. So my ad-hoc solution was the following on about line 860 of /includes/functions/functions_general.php:

function zen_db_input($string) {
if (is_string($string)){ // ADDED to eliminate PHP warnings in myDEBUG logs related to input not being strings
return addslashes($string);
} else {
return $string;
}
}

> 
> If anyone can think of a better solution or knows of a reason why I should not return an unprocessed string please let me know. As far as I can tell, the only thing that will happen to array content is that it will be written to the db as "Array" which may be more helpful than nothing. This assumes, of course, that the is_string() native PHP function can accurately determine string content and not let through something it shouldn't.

I wonder if you might be on to something...
I have  just pm'd Andrew to ask him to take a look at  this thread.
9 May 2013, 6:38 AM
#10
openvista avatar

openvista

New Zenner

Join Date:
Sep 2009
Posts:
23
Plugin Contributions:
0

Post #10 by openvista

DrByte:

It would be much safer to fix the data being passed, since what you've suggested bypasses the sanitizing that was intended, and if the data isn't actually already reliably clean you could be introducing a SQL Injection risk by your change.

After some testing I've found that continuing to pass the data along when it's actually an array doesn't work since other dependent functions assume a string value when they execute zen_db_input(). So the warning remains in the log regardless. I've also tried just the first half of the conditional which implicitly blocks all but strings from being returned. This results in the login form no longer working (I'm sure that's just the beginning of problems it creates).

So I've taken Dr Byte's advice (as I was nervous in the first place with my duct-taped solution leading to SQL injection), rolled back the functions_general.php code and gone searching for a solution at the source of the problem. I'll move over to the Supertracker support thread (http://www.zen-cart.com/showthread.php?65040-Supertracker/page31) to discuss this particular issue.

Thanks for the help!

10 May 2013, 1:19 PM
#12
picandnix avatar

picandnix

Totally Zenned

Join Date:
Dec 2010
Location:
UK
Posts:
1,779
Plugin Contributions:
2

Post #12 by picandnix

picandnix:

Haven't tried it yet but here's Andrew's answer...
http://www.zen-cart.com/showthread.php?65040-Supertracker&p=1202465#post1202465

a_berezin:

Quick bug fix.
includes/class/supertracker.php
Search

$cart_contents = unserialize($tracking_data->fields['cart_contents']);

> replace by
> ```php
$cart_contents = $tracking_data->fields['cart_contents'];

It works! :smile:
thank you Andrew