nitsua01 Posted July 30, 2014 Share Posted July 30, 2014 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); }?> Quote Link to comment https://forums.phpfreaks.com/topic/290196-figuring-out-the-cuteflow-issue/ Share on other sites More sharing options...
mac_gyver Posted July 30, 2014 Share Posted July 30, 2014 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) Quote Link to comment https://forums.phpfreaks.com/topic/290196-figuring-out-the-cuteflow-issue/#findComment-1486508 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.