Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,263
    Plugin Contributions
    3

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

    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

  2. #2
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,263
    Plugin Contributions
    3

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

    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

  3. #3
    Join Date
    Dec 2010
    Location
    UK
    Posts
    1,771
    Plugin Contributions
    3

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

    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?

  4. #4
    Join Date
    Dec 2010
    Location
    UK
    Posts
    1,771
    Plugin Contributions
    3

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

    Actually it could be when removing item from cart?

  5. #5
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

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

    Quote Originally Posted by schoolboy View Post
    ... 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.

  6. #6
    Join Date
    Sep 2009
    Posts
    23
    Plugin Contributions
    0

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

    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:

    Code:
      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.
    Last edited by openvista; 9 May 2013 at 02:11 AM.

  7. #7
    Join Date
    Jan 2007
    Location
    Los Angeles, California, United States
    Posts
    10,023
    Plugin Contributions
    32

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

    Quote Originally Posted by picandnix View Post
    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.

  8. #8
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

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

    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. #9
    Join Date
    Dec 2010
    Location
    UK
    Posts
    1,771
    Plugin Contributions
    3

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

    Quote Originally Posted by openvista View Post
    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:

    Code:
      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.

  10. #10
    Join Date
    Sep 2009
    Posts
    23
    Plugin Contributions
    0

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

    Quote Originally Posted by DrByte View Post
    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.p...tracker/page31) to discuss this particular issue.

    Thanks for the help!

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v153 PHP Warning: addslashes() expects parameter 1 to be string
    By BlackOrchidCouture in forum General Questions
    Replies: 2
    Last Post: 17 Sep 2014, 10:47 PM
  2. Warning: trim() expects parameter 1 to be string, array given
    By jpietrowiak in forum General Questions
    Replies: 2
    Last Post: 8 Jun 2013, 07:06 PM
  3. v139e PHP Warning: strlen() expects parameter 1 to be string, array given in
    By irishshopper in forum Basic Configuration
    Replies: 4
    Last Post: 7 Mar 2013, 08:06 PM
  4. v139h PHP Warning: strip_tags() expects parameter 1 to be string, array given
    By BlessIsaacola in forum General Questions
    Replies: 1
    Last Post: 6 Mar 2012, 01:32 PM
  5. v150 PHP Warning: strlen() expects parameter 1 to be string, array given
    By caffeitalia in forum General Questions
    Replies: 1
    Last Post: 1 Feb 2012, 03:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR