2017-05-04 7 views
0

私は、ファイルindex.phpとAdminSite.phpを持つフォルダを持っています。 AdminSite.phpをクエリ文字列 "domain.com/index.php?section=admin/"で表示するにはどうすればよいですか?セクションとしてPHPファイルを使用するには

(私の文法が正しくない場合は、私を修正してください:D)

+0

AdminSite.phpをindex.phpのセクションとして表示しますか?あなただけでそれを含めることができます。 –

+0

@ chris85ありがとう、それは動作します:D – Deeonix

答えて

0

あなたは条件付きとincludeファイルを使用することができます。

if(!empty($_GET['section']) && $_GET['section'] == 'admin/') { 
    include 'AdminSite.php'; 
} 
0

(AdminSite.phpは、index.phpのと同じディレクトリにあると仮定して)このような何か:

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

    if($section && $section == 'admin'){ 
     include('AdminSite.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]); 
    } 
?> 
関連する問題