私は、ファイルindex.phpとAdminSite.phpを持つフォルダを持っています。 AdminSite.phpをクエリ文字列 "domain.com/index.php?section=admin/"で表示するにはどうすればよいですか?セクションとしてPHPファイルを使用するには
(私の文法が正しくない場合は、私を修正してください:D)
私は、ファイルindex.phpとAdminSite.phpを持つフォルダを持っています。 AdminSite.phpをクエリ文字列 "domain.com/index.php?section=admin/"で表示するにはどうすればよいですか?セクションとしてPHPファイルを使用するには
(私の文法が正しくない場合は、私を修正してください:D)
あなたは条件付きとinclude
ファイルを使用することができます。
if(!empty($_GET['section']) && $_GET['section'] == 'admin/') {
include 'AdminSite.php';
}
(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]);
}
?>
AdminSite.phpをindex.phpのセクションとして表示しますか?あなただけでそれを含めることができます。 –
@ chris85ありがとう、それは動作します:D – Deeonix