I have an old calculator on one of my websites and after recently noticed that it no longer loads (the code is pretty ancient). It just displays a white blank page with no errors. The only error I could find was in the server error log that says:
PHP Warning: Illegal string offset 'action' in /home/o8ap61wv26c5/public_html/calculator.php on line 13
this is the code it is referring to:
$param = get_request_var('param');
if($param['action'] == 'calculate'){
$param['principal'] = preg_replace('/[^0-9\.]/', '', $param['principal']);
if($param['principal'] < $config['min_principal'] || $param['principal'] > $config['max_principal']) $err['principal'] = true;
if($param['interest_rate'] < $config['min_interest_rate'] || $param['interest_rate'] > $config['max_interest_rate']) $err['interest_rate'] = true;
if($param['start_year'] < $config['min_start_year'] || $param['start_year'] > $config['max_start_year']) $err['start_year'] = true;
if($param['start_month'] < 1 || $param['start_month'] > 12) $err['start_month'] = true;
if($param['term'] < $config['min_term'] || $param['term'] > $config['max_term']) $err['term'] = true;
}
and this is the function code
function get_request_var($varname = '', $defaultval = '') {
global $smarty;
if($varname){
if(isset($_POST[$varname])){
$var = $_POST[$varname];
} elseif(isset($_GET[$varname])) {
$var = $_GET[$varname];
}
} elseif(count($_POST)) {
$var = $_POST;
} elseif(count($_GET)) {
$var = $_GET;
}
$smarty->load_filter('output', 'correctoutput');
if(isset($var)){
/* assign variable to Smarty */
if(isset($smarty)){
if(get_magic_quotes_gpc()){
$smarty->assign($varname, array_stripslashes($var));
} else {
$smarty->assign($varname, $var);
}
}
/* adding slashes if magic quotes feature is turned off */
if(!get_magic_quotes_gpc()) $var = array_addslashes($var);
return $var;
} else {
$smarty->assign($varname, $defaultval);
return $defaultval;
}
}
any idea why the page would give this error? Also worth mentioning is that I recently moved serves php 5.6
CodePudding user response:
You have to check if action exists in your params
if ( isset ( $param['action'])) {}
nice way to print your indexes :
echo "<pre>".print_r($param, true)."</pre>";
For the why it's not working anymore, maybe your server change it's version of it error reporting is not higher than before ?
CodePudding user response:
I had to modify php configuration through a php.ini file. By default, this setting was turned off on my new server.
zlib.output_compression = On