Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> [php] Prevent Copying A Template For Each New Page
rustypaulin
post Aug 3 2005, 10:28 AM
Post #1


Super Member
*********

Group: Members
Posts: 309
Joined: 8-March 05
Member No.: 4,273



This code means every time you make a page you don't need to copy and paste the HTML code for your template, this can make editing links, especially those that appear on every page, and pages a lot easier.

1. Make sure that your template is coded so it is fully expandable.

2. Insert this code into the content area of your template, and save the file as index.php, instead of .html

QUOTE
<?
$val = $_GET['id']; // Replace id with whatever you want to use, eg ?id=page
$val .= ".html"; // Makes the filename complete so if you called ?id=index, it would be index.php it has to look for
$dirty = array("..");
$clean = array("");
$val = str_replace($dirty, $clean, $val); // Prevent people from viewing root files like your password

if (isset($_GET['id'])) { // Replace id with whatever you want to use, eg ?id=page
if (file_exists($val)) { // This checks if the file you are trying to call exists
include "$val";
}
else {
include "404.php"; // If the file doesnt exists it calls your 404 error page
}
}
else {
include "home.html"; // If ?id= is not set it will now go to your news page
}
?>


You will also need a file called home.html, that should contain what you want displayed on your home page.

3. Whenever you make a new page you just need to write the content you want included on the page, you won't need the template at all.

So to make a news page you make a file called news.html write the content you want in it, and the link to get to it would be "index.php?id=news"

The main advantage of this script is for when you have links, affiliates, etc displayed on your website that appear on every page and they might need to be changed, so this will make it far faster than having to go through every page to do this.

For your links you would make a new page called links.html and write all your links in it. Then you would put
QUOTE
<? include("links.html") ?>

where ever you want your links to go. Then when you want to edit the links you only need to edit one page instead of numerous other ones.

I hope you find my tutorial useful.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Dreamweaver Or Front Page Or Other?(108)
  2. Php Unique Hit Counter(28)
  3. Toggle display in page script(8)
  4. Whow to change template on php nuke(4)
  5. Refresh Web Page(6)
  6. Cpanel Demo Page(44)
  7. Open Php Page From Another Server(7)
  8. Refresh Page After Back Button Hit(9)
  9. Wap Source Code Viewer(4)
  10. Check Referrer To Prevent Linking Yours From Other Sites(8)
  11. Web Page Tree Menu: Style Sheet - Javascript(5)
  12. Error Code In Subscriptions Page(5)
  13. Envizion's Front Page(12)
  14. Does Pro Active Work ?(8)
  15. Create A Google Seach Result Page Embed Within Your Site Page.(12)
  1. Web Page Layouts(1)
  2. Create Page?(11)
  3. Ways To Destress And Prevent Yourself From Bingeing(5)
  4. Orkut Copying Facebook !(5)
  5. I Cant Log In To Cpanel(6)
  6. Multiple Page Titles(1)
  7. Html Page Not Showing Up In Firefox(1)
  8. What Is Your Home Or Start Page?(14)
  9. Iso Graphic Designer For Website Template(0)
  10. Template Chooser?(10)
  11. How To Make An Item Scroll With You On The Page.(9)
  12. How Do I Get Rid Of The Placeholder Page? [resolved](5)
  13. Page Load Error When Accessing Cpanel(0)


 



- Lo-Fi Version Time is now: 4th July 2008 - 08:50 PM