如何使用PHP文件作为节

如何使用PHP文件作为节,php,html,apache2,php-7,Php,Html,Apache2,Php 7,我有一个包含index.php和AdminSite.php文件的文件夹。现在如何使用查询字符串“domain.com/index.php?section=admin/”显示AdminSite.php (如果我的语法不正确,请纠正我:D)您可以使用条件和文件 if(!empty($_GET['section']) && $_GET['section'] == 'admin/') { include 'AdminSite.php'; } 类似这样(假设AdminSite

我有一个包含index.php和AdminSite.php文件的文件夹。现在如何使用查询字符串“domain.com/index.php?section=admin/”显示AdminSite.php


(如果我的语法不正确,请纠正我:D)

您可以使用条件和文件

if(!empty($_GET['section']) && $_GET['section'] == 'admin/') {
     include 'AdminSite.php'; 
}
类似这样(假设AdminSite.php与index.php位于同一目录中):


如果要对其他部分执行此操作,则可以是这样的:

<?php
    $section = $_GET['section'];

    if($section){
        switch($section){
            case 'admin':
                include('AdminSite.php');
                break;
            case 'contacts':
                include('Contacts.php');
                break;
        }
    }
?>
<?php
    $section = $_GET['section'];

    $sections = [
        'admin' => 'AdminSite.php',
        'contacts' => 'Contacts.php',
        // add your sections here
        // 'section from url' => 'path to file'
    ];

    if($section && file_exists($sections[$section])){
        include($sections[$section]);
    }
?>

或者像这样:

<?php
    $section = $_GET['section'];

    if($section){
        switch($section){
            case 'admin':
                include('AdminSite.php');
                break;
            case 'contacts':
                include('Contacts.php');
                break;
        }
    }
?>
<?php
    $section = $_GET['section'];

    $sections = [
        'admin' => 'AdminSite.php',
        'contacts' => 'Contacts.php',
        // add your sections here
        // 'section from url' => 'path to file'
    ];

    if($section && file_exists($sections[$section])){
        include($sections[$section]);
    }
?>


是否将AdminSite.php显示为index.php中的一个部分?你可以把它包括在里面。@chris85谢谢,它是有效的:D