Best way to avoid code injection in PHP

前端 未结 10 1191
臣服心动
臣服心动 2020-12-01 05:29

My website was recently attacked by, what seemed to me as, an innocent code:



        
10条回答
  •  粉色の甜心
    2020-12-01 06:02

    Use a whitelist and make sure the page is in the whitelist:

      $whitelist = array('home', 'page');
    
      if (in_array($_GET['page'], $whitelist)) {
            include($_GET['page'].'.php');
      } else {
            include('home.php');
      }
    

提交回复
热议问题