Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

PHP template script

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

TwiztedFake

Established Member
Impact
1
I come up with this after getting really tired of updating multiple files when ever I wanted to make a site wide layout change. It does require use of PHP, which means your pages have to be .php instead of .htm, .html

Its is a bit of code that allows you to create one layout file and load all of your content into that layout.

Code:
<?php
$config["path"] = "LOCATION OF YOUR CONTENT TO LOAD";
$config["ext"] = EXTENSION OF THE CONTENT FILES EX. .php, .htm, .txt";

if (!isset($_REQUEST["page"])){
    $page = "main";
} else {
    $page = $_REQUEST["page"];
    $page = urldecode($page);
    $page = trim($page);
    $page = strip_tags($page);
    if (substr_count($page,"..") > 0 || substr_count($page,"~") > 0){
        $page = "main";
    }
}
$full = $config["path"] . $page . $config["ext"];
if (!is_file($full) || is_dir($full) || !file_exists($full)){
    die ("Sorry, the page you are looking for is gone. Please email the webmaster with the URL currently in your address bar so that it can be corrected. Thanks!");
} else {
    require_once($full);
}
?>

To use this simply design your layout and place this where you want you content to load. Create your content files.
Now your links will look like this:
Code:
<a href="index.php?page=filename>Content</a>

Instead of having to search through all the lines of code to update content you can keep the content and layout seperate. Just a note with how I posted the code a file called 'main' will load when the page is opened for the first time. You can chage this by editing the line $page = "main"; to reflect the filename you would like to load when first accessed.
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
its not working for me, this is what ive got

Code:
<?php
$config["path"] = "http://barkus.f2s.com/sbnew";
$config["ext"] = ".php";

if (!isset($_REQUEST["page"])){
    $page = "main";
} else {
    $page = $_REQUEST["page"];
    $page = urldecode($page);
    $page = trim($page);
    $page = strip_tags($page);
    if (substr_count($page,"..") > 0 || substr_count($page,"~") > 0){
        $page = "main";
    }
}
$full = $config["path"] . $page . $config["ext"];
if (!is_file($full) || is_dir($full) || !file_exists($full)){
    die ("Sorry, the page you are looking for is gone. Please email the webmaster with the URL currently in your address bar so that it can be corrected. Thanks!");
} else {
    require_once($full);
}
?>

i added a file called main.php which is the content that i want to show up on the first page of the site (index.php)
 
0
Close
On this line: $config["path"] = "http://barkus.f2s.com/sbnew";

You need to add a / after sbnew and that should fix the problem.
 
0
Close
Might be useful but i did it a much, well easier way?

I just included my header(layout), content, then footer. I might try this one in the future. Nice script
 
0
Close
.:Mammoth261:. said:
Might be useful but i did it a much, well easier way?

I just included my header(layout), content, then footer. I might try this one in the future. Nice script

Yes that works too but then you have multiple files to edit when making a layout change. With this your layout is one page which loads the content when called upon. All content is stored in seperate files (simple text and formating tags ex: h1, h2, p, table, etc.) away from the layout.
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back