Jump to content

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)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.