Jump to content

Recommended Posts

This PHP program has been haunting IT around the world, see if you can correct it? Its open source code!

 

Errors:

 

Notice: Uninitialized string offset: 0 in C:\wamp\www\language_files\language.inc.php on line 33

Notice: Undefined offset: 2 in C:\wamp\www\language_files\language.inc.php on line 50

 

 

 

Code:

 

<?php

 $strLangShort   = $_REQUEST['language'];
 if ($strLangShort == '')
 {
  $strLangShort   = $_REQUEST['strLanguage'];
 }
 $strFilename  = 'gui_'.$strLangShort.'.langprop';
 $strLanguagePath = "../language_files/".$strFilename;

 $pFile = @fopen($strLanguagePath, "r");
 if ($pFile == null)
 {
  $strLanguagePath = "language_files/".$strFilename;
 
  $pFile = @fopen($strLanguagePath, 'r');
  
  if ($pFile == null)
  {
   $strLanguagePath = "../../language_files/".$strFilename;
  
   $pFile = @fopen($strLanguagePath, 'r');
  }
 }
 
 $arrTranslation;
 if (null != $pFile)
 {
  while (!feof ($pFile))
  {
      $strLine = trim(fgets($pFile, 4096));
     
      if ( ($strLine[0] != "#") && (strlen($strLine) > 0) && (substr($strLine,0,5)!="_jotl"))
      {      
       $nPos = strpos($strLine, "=");
       $strId = substr($strLine, 0, $nPos);
       $strRest = trim(substr($strLine, $nPos+1));
             
       $arrInfos = explode("@@@", $strRest);
       $strValue = $arrInfos[0];
       
       $arrTranslation[$strId] = $strValue;
      }
      else
      {
       $nPos    = strpos($strLine, "=");
       $strConfig   = substr($strLine, 0, $nPos);
       $splitConfig  = explode (".", $strConfig);
       
       if ($splitConfig[2] == 'encoding')
       {
        $DEFAULT_CHARSET = trim(substr($strLine, $nPos+1));
       }
      }
  }  
  fclose($pFile);
 }
 $CIRCULATION_MNGT_ADDCIRCULATION;
 
 
 foreach($arrTranslation as $key => $value)
 {
  $$key = $value;
 }
 
 function escapeSingle($string)
 {
  return str_replace("'", "\\'", $string);
 }
 
 function escapeDouble($string)
 {
  return str_replace("\"", "\\\"", $string);
 }
?>

Link to comment
https://forums.phpfreaks.com/topic/290196-figuring-out-the-cuteflow-issue/
Share on other sites

that's some pretty sad code. there's even someone that posted a bug/solution on the cuteflow site that got the reason for the error wrong, which got his solution to prevent the errors but didn't fix what the code is actually doing.

 

the problem is that empty lines in the language file will be an empty string in the php data, producing errors when you try to access specific characters of the string or parts of an explode empty string that won't exist. also, the lines starting with # are apparently (there's no documentation) commented out lines and shouldn't be processed at all.

 

the simplest fix, for just the incorrect logic, is to change the following line - 

 if ( ($strLine[0] != "#") && (strlen($strLine) > 0) && (substr($strLine,0,5)!="_jotl"))

to this - 

if(strlen($strLine) > 0 && $strLine[0] != "#") // not an empty line and not a commented out line
if (substr($strLine,0,5)!="_jotl") // for lines not starting with _jotl (the else block is for lines starting with _jotl)
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.