如何清理我的包含语句?

2022-01-25 00:00:00 include security php

如何清除此问题以使用户无法将页面拉出本地域?

How do I clean this so users can't pull pages outside of the local domain?

<?php
 if(!empty($_GET['page']))
 {
  include($_GET['page']);
 }
 else
 {
  include('home.php');
 }
?>

推荐答案

最安全的方法是将您的页面列入白名单:

The safest way is to whitelist your pages:

$page = 'home.php';

$allowedPages = array('one.php', 'two.php', ...);

if (!empty($_GET['page']) && in_array($_GET['page'], $allowedPages))
    $page = $_GET['page'];

include $page;

相关文章