동적 인 PHP 인클루드는 어떻게 만들 수 있습니까? 예를 들어, 내가 그 안에 포함 header.php와 footer.php과 index.php 파일이 그래서 배열과 케이스를 사용하는 것은 동적 필요가 가능한 경우안전한 동적 PHP가 포함되어 있습니까?
index.php?page=about
를 사용 inbetween 다른 페이지를 잡아 시간이 많이 걸리고 수정이 필요합니다.
또한 어떤 페이지가 포함되어 있는지에 따라 웹 사이트의 제목도 변경할 수 있기를 원합니다.
나는 현재이 자리에 있습니다
<?php
require_once 'includes/config.php';
//Set values for page
$page_title = 'home page';
$current_page = 'home';
require_once 'includes/header.php';
?>
CONTENT
<?php
require_once 'includes/footer.php';
?>
감사
이 내 페이지를 포함 할 수있는 안전한 방법이 될 것인가?
if(isset($_GET[ 'page' ]))
{
if(strpos($_GET[ 'page' ], "/"))
{
$dir = substr(str_replace(’’, ”, $_GET[ 'page' ]), 0, strpos($_GET[ 'page' ], "/")) . "/";
$file = substr(strrchr($_GET['page' ], "/"), 1);
if(file_exists($dir.$file.".php"))
{
include($dir.$file.".php");
} else {
include("home.php");
}
} else {
if(file_exists(basename($_GET[ 'page' ]).".php"))
{
include(basename($_GET[ 'page' ]).".php");
} else {
include("404.php");
}
}
} else {
include("home.php");
}
http://stackoverflow.com/questions/11354484/how-to-include-page-with-get-function-htaccess-linking/11354526#11354526 – Austin
romo의 답변을 언급하는 경우이 내 질문에 대답. 그것은 제 질문의 두 번째 부분과 관련이 있습니다. 그러나 나는 파일 이름을 제외하고 그 방법을 사용하여 제목이 말할 내용에 대해 아무런 통제권이 없다. – Sygon
예, 스위치 내에서 $ page_title 변수를 설정하기 만하면됩니다. 나는 위의 링크에 게시 된 답변을 언급하고 있습니다. – Austin