Home  >  Article  >  Backend Development  >  Solution to Notice: Undefined index error message in php

Solution to Notice: Undefined index error message in php

WBOY
WBOYOriginal
2016-07-25 09:03:591357browse
  1. if(array_key_exists( 'istrue',$_POST))
  2. {
  3. if($_POST[ 'istrue'])
  4. {
  5. $istrue=$_POST[ 'istrue'];
  6. }
  7. }else{
  8. $istrue='';
  9. }
Copy the code

The subsequent judgment can be as follows

  1. elseif ($istrue == 'ok')
Copy the code

to avoid such errors. You can refer to how to do some program systems. For details, please refer to the code of dedecms or phpcms.

  1. //Check and register externally submitted variables

  2. foreach($_REQUEST as $_k=>$_v)
  3. {
  4. if( strlen($_k)> ;0 && eregi('^(cfg_|GLOBALS)',$_k) )
  5. {
  6. exit('Request var not allow!');
  7. }
  8. }
  9. function _RunMagicQuotes(&$svar)
  10. {
  11. if(! get_magic_quotes_gpc())
  12. {
  13. if( is_array($svar) )
  14. {
  15. foreach($svar as $_k => $_v) $svar[$_k] = _RunMagicQuotes($_v);
  16. }
  17. else
  18. {
  19. $svar = addslashes($svar);
  20. }
  21. }
  22. return $svar;
  23. }

  24. foreach(Array('_GET','_POST','_COOKIE') as $_request )

  25. {
  26. foreach($$_request as $_k => $_v) ${$_k} = _RunMagicQuotes($_v);
  27. }
  28. if(empty($istrue))
  29. {
  30. $istrue = '';
  31. }

Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn