PHP Notice: Undefined index error prompt solution

  • 2020-03-31 21:05:40
  • OfStack

The first method: if it does not affect the normal execution of the program, you can use the method of shielding

You can add it to the first line of code
Error_reporting (E_ALL ^ E_NOTICE);

Turn off the NOTICE error warning

The second method: locate the specific line and solve it according to the prompt.
For example, elseif ($_POST['istrue'] == 'ok'), the code above, did not commit this istrue, so there must be a problem.

This can be solved with the following code
Judge from above

if(array_key_exists( 'istrue',$_POST)) 
{ 
if($_POST[ 'istrue']) 
{ 
$istrue=$_POST[ 'istrue']; 
} 
}else{ 
$istrue=''; 
}

The following judgment can be made

elseif ($istrue == 'ok')

You can avoid this kind of error, you can refer to some procedures of the system is how to do.
Specific can refer to the dedecms live PHPCMS code

//Check and register externally committed variables
foreach($_REQUEST as $_k=>$_v) 
{ 
if( strlen($_k)>0 && eregi('^(cfg_|GLOBALS)',$_k) ) 
{ 
exit('Request var not allow!'); 
} 
} 
function _RunMagicQuotes(&$svar) 
{ 
if(!get_magic_quotes_gpc()) 
{ 
if( is_array($svar) ) 
{ 
foreach($svar as $_k => $_v) $svar[$_k] = _RunMagicQuotes($_v); 
} 
else 
{ 
$svar = addslashes($svar); 
} 
} 
return $svar; 
} 

foreach(Array('_GET','_POST','_COOKIE') as $_request) 
{ 
foreach($$_request as $_k => $_v) ${$_k} = _RunMagicQuotes($_v); 
} 
if(empty($istrue)) 
{ 
$istrue = ''; 
}

Related articles: