I am making a website and have a pretty strong template that I have made. Of course, I need to make changes to it once and a while and would like to figure out a way to make changes to only one .php file rather than having to change 10+ different files. There has to be a way to do this in php, I just do not know where to look.
The easiest way to do this is to create a separate file which you can use as an include file in your scripts.
for instance, here a header script:
<?php
$title = 'this is the title';
?>
and name it something like header.php
Then all you need to do is to put something like this in each page that has the updates:
include_once('header.php');
you can do it by using htaccess, make rewrite rule like this
make index.php with your template and blank file demo.php
RewriteRule ^home$ index.php RewriteRule ^Demo$ index.php?page=demo.php
and put this code in your body part of index.php file
$page = isset ( $_REQUEST [ 'page' ] ) ? $_REQUEST [ 'page' ] : 'home' ;
if ( $page !== 'home' && strlen ( $page ) > 0 ) {
$file = sprintf ( '%s' , $page ) ;
if ( file_exists ( $file ) ) {
require_once $file ;
};
} else require_once 'default page you wanna show' ;
and brows to www.yoursite/Demo
you will redirect to demo.php with your theme