Zen Cart Logo
Forums / Bug Reports / PHP Warning: Invalid UTF-8 sequence in argument in /ajax.php on line 24

PHP Warning: Invalid UTF-8 sequence in argument in /ajax.php on line 24

Views: 3,936

Results 1 to 10 of 10
25 Mar 2015, 11:06 AM
#1
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,699
Plugin Contributions:
56

PHP Warning: Invalid UTF-8 sequence in argument in /ajax.php on line 24

PHP Warning: Invalid UTF-8 sequence in argument in /ajax.php on line 24

Prior to

      echo json_encode ($result);exit();

should there be something like

      $result = htmlentities((string)$result, ENT_QUOTES, 'utf-8', FALSE); 
25 Mar 2015, 11:32 AM
#2
drbyte avatar

drbyte

Sensei

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

Re: PHP Warning: Invalid UTF-8 sequence in argument in /ajax.php on line 24

Can you describe the steps you took to trigger the error message?

25 Mar 2015, 10:03 PM
#3
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,699
Plugin Contributions:
56

Re: PHP Warning: Invalid UTF-8 sequence in argument in /ajax.php on line 24

Checkout by credit card (Paypal Express) with this item - the checkout confirmation page is blank in the center column, but the remainder of the page including the footer do render.

The fix I suggested above seems to resolve this issue.

14 Oct 2015, 7:40 PM
#5
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,089
Plugin Contributions:
56

Re: PHP Warning: Invalid UTF-8 sequence in argument in /ajax.php on line 24

FWIW, this change breaks one of my commercial plugins. That plugin returns an ***array ***of information to an AJAX request and the suggestion of simply casting the result to a string wrecks havoc!

Here's the change that I made, allowing the return values to be string-value-containing-names or array elements:

<?php
/**
 * ajax front controller
 *
 * @package core
 * @copyright Copyright 2003-2015 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version GIT: $Id: Author: Ian Wilson   Modified in v1.6.0 $
 */
require ('includes/application_top.php');

//-bof-lat9  *** 1 of 2 ***
function htmlentities_mixed ($mixed_value, $flags, $encoding = 'utf-8', $double_encode = true) {
  if (!is_array ($mixed_value)) {
    $result = htmlentities ((string)$mixed_value, $flags, $encoding, $double_encode);
    
  } else {
    $result = array ();
    foreach ($mixed_value as $key => $value) {
      $result[$key] = htmlentities_mixed ($value, $flags, $encoding, $double_encode);

    }
  }
  return $result;
  
}
//-eof-lat9  *** 1 of 2 ***

$language_page_directory = DIR_WS_LANGUAGES.$_SESSION['language'].'/';
if (isset ($_GET['act'])&&isset ($_GET['method'])) {
  $className = 'zc'.ucfirst ($_GET['act']);
  $classFile = $className.'.php';
  if (file_exists (DIR_FS_CATALOG.DIR_WS_CLASSES.'ajax/'.$classFile)) {
    require (DIR_FS_CATALOG.DIR_WS_CLASSES.'ajax/'.$classFile);
    $class = new $className ();
    if (method_exists ($class, $_GET['method'])) {
      $result = call_user_func (array(
          $class,
          $_GET['method']
      ));
      
//-bof-lat9  *** 2 of 2 ***
      $result = htmlentities_mixed ($result, ENT_QUOTES, 'utf-8', FALSE);
//-eof-lat9  *** 2 of 2 ***

      echo json_encode ($result);exit();
    } else {
      echo 'method error';
    }
  }
}
14 Oct 2015, 7:46 PM
#6
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,699
Plugin Contributions:
56

Re: PHP Warning: Invalid UTF-8 sequence in argument in /ajax.php on line 24

lat9:

FWIW, this change breaks one of my commercial plugins....

What is the name of the plugin (so folks who are searching will come to this thread)?

14 Oct 2015, 8:13 PM
#7
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,089
Plugin Contributions:
56

Re: PHP Warning: Invalid UTF-8 sequence in argument in /ajax.php on line 24

That plugin's name is Products Options Stock Manager (POSM).

16 Oct 2015, 3:58 PM
#8
drbyte avatar

drbyte

Sensei

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

Re: PHP Warning: Invalid UTF-8 sequence in argument in /ajax.php on line 24

Proposed code change slated for v160: https://github.com/zencart/zencart/pull/613
For v1.5.x the code by lat9 should be fine, and only involves touching 1 file.

16 Oct 2015, 4:03 PM
#9
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,089
Plugin Contributions:
56

Re: PHP Warning: Invalid UTF-8 sequence in argument in /ajax.php on line 24

Thanks, DrByte!

11 Dec 2015, 10:35 PM
#10
drbyte avatar

drbyte

Sensei

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

Re: PHP Warning: Invalid UTF-8 sequence in argument in /ajax.php on line 24

I'm investigating reports of the previously-proposed "fix" being an incomplete, and potentially buggy, approach.

To that end, I'm looking for any information any of you can provide to help me trigger the exact same symptoms with PayPal Pro on v154. Basically looking for details on how to set up a test site with settings to match yours in a way that I can trigger the symptoms ... so I can ensure we come up with as complete a fix as possible.

Feedback welcome ;)