Jump to content

Making a site template with PHP includes


Perry|

Recommended Posts

Hello.

 

I am making a site template with php includes, however, I have lots of things I need in the template and I do not know how to do them as I am fairly new to PHP.

 

Here is an idea of what I want to the site look like

 

design.png

 

Yellow areas are the template, red areas are the template but are adverts and the blue area is what is dynamic and will be changed on the page type via creating a new php document, copying the template from a text file on the server then including the file with the data in the specific place. So could someone post example code so I can learn off of it or something  :-\

 

In the blue area I will be using

include("./s/file".$_GET['id'].".php")

 

Will it work with the template aswell?

 

I am really new to PHP so I need extra help with all of this.

 

Regards,

 

Perry

If you want everything to stay the same except the blue area, you may wish to try:

 

<?php
if (isset($_GET['id'])) 
{
$id = $_GET['id'];
} else {
$id = 'default';
}
if (preg_match('/^[a-z0-9_-]+$/i', $id)) 
{
require('./' . $id . '.php');
} 
else 
{
die('Invalid Input');
}
?>

 

This will allow you to change the blue area (with a link like index.php?id=foo), whilst not affecting the rest of the index.php template. The preg_match code is to make sure it cannot be exploited. Also, note the 'else', which means that if no ID is called, then it should display 'default'.php (or whatever page you want)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.