Reputation: 986
I've written some code that includes 'home.php' if the URL contains 'index.php':
<?php if($_GET['page'] != "index.php") {
include('_includes/home.php'); } ?>
This works fine for a specific page (in this instance the home page), but I want to extend this logic for any page on my site. For instance if the URL contained 'foo2.php' I'd want the the PHP to search for and include '_includes/foo2.php'.
I'm new to php so any help would be appreciated.
Upvotes: 0
Views: 97
Reputation: 3280
How about:
if(isset($_GET['page'])) include "_includes/{$_GET['page']}.php";
Upvotes: 0
Reputation: 5524
if the URL was:
if (empty($_GET['page'])){
include ("_includes/index.php");
exit;
}
$Page_Search = glob("_includes/*.php");
if (in_array($_GET['page'],$Page_Search)){
include ("_includes/$page.'.php');
exit;
}
This might be of use.
Upvotes: 1