Scripts
NL-ConvertToPHP
-
NL-ConvertToPHP
Released on January 8, 2004, Last Updated on April 29, 2008
Written by
Sasha
Added by Sasha (view more by Sasha)
NL-ConvertToPHP allows you to easily convert your site to a PHP site, or optimize your current PHP coding. The advantages of using this method include 1) less pages to edit/upload, all your content will be in one file; 2) shorter urls, it will be index.php?about instead of index.php?z=about.php; 3) faster loading pages because of less coding. This method uses only one line of PHP coding per section, so there’s very little to edit for you, you will have it up and running in no time.
Always wanted to convert your site to PHP, but always too intimidated to try? Read on, because I have here the easiest and fastest way to convert your site to PHP.
Are you already using PHP on your site? Then read on anyway, because the coding used here is optimized, for faster page loading and less hassle for you.
This script will allow you to put the content for all of your pages into one file, and will display the content needed depending on what url you send your visitors to. The advantages over other PHP conversion scripts you may have seen:
- All your content will be in one file. No more index.php, about.php, rules.php, codes.php etc…everything will be in index.php. Only one file to edit and upload and it takes up less space on your server.
- Shorther URLs. It will be index.php?about instead of index.php?z=about.inc
- Faster loading pages. Since the content is all inside the one page, the PHP script doesn’t have to go and get other files off the server, making your pages load faster.
- Less coding. One line of PHP code will do all this for you.
Install
I’ll show you how to do this by example. Say you want to use this on a fanlisting you own. You would normally have the following pages: index, about, rules, join, codes, members and extra.
Open up all these pages in your HTML editor, and then create a blank page in Notepad/Editpad/your text editor of choice. Paste the following code into the blank page, and save it as index.php (or any other name you like…as long as the extension is .php).
<?php
//Copy and paste the HTML that is the same in all your pages (the header and footer) into new files and name them header.php and footer.php.
//They will be included at the complete top and bottom of your pages, so you will only have to edit these 2 files if you want to change your layout.
include 'header.php';
if (!$_SERVER['QUERY_STRING']) { ?>
//Paste here the HTML coding you have on your main page. This is what people will see when they go to index.php, without any ?section bit after it.
<?php } elseif ($_SERVER['QUERY_STRING'] == "about") { ?>
//Paste here your HTML code on the About page (without the header and footer code, obviously).
<?php } elseif ($_SERVER['QUERY_STRING'] == "rules") { ?>
//Paste here your HTML code on the Rules page (without the header and footer code, obviously).
<?php } elseif ($_SERVER['QUERY_STRING'] == "join") { ?>
//Paste here your HTML code on the Join page (without the header and footer code, obviously).
<?php } elseif ($_SERVER['QUERY_STRING'] == "codes") { ?>
//Paste here your HTML code on the Codes page (without the header and footer code, obviously).
<?php } elseif ($_SERVER['QUERY_STRING'] == "members") { ?>
//Paste here your HTML code on the Members page (without the header and footer code, obviously).
<?php } elseif ($_SERVER['QUERY_STRING'] == "extra") { ?>
//Paste here your HTML code on the Extra page (without the header and footer code, obviously).
<?php }
include 'footer.php'; ?>
Read the code carefully and look for the lines that start with //. They are comments, and explain what and where you need to change something. If you have any problems with it, or any questions about this script, please feel free to post about it at the forums.
Please note that the page you are inserting this code into has to have a .php extension, otherwise it won’t work!!
You can add as many of the elseif lines as you want to, and you can name them anything you want. Just remember that in order to access that section, you will need the url to be index.php?yourname, with yourname being what you changed the text in quotation marks (in the example above, that would be about, rules join, etc.) to.
For my larger sites, I prefer to split the site up into sections (such as site, about the person and media), and have the coding above pasted into those php pages (so all the media things, such as images, audio and video will be in media.php, all site related sections such as about, credits, link me, affiliates etc. are in the site.php page and so on). That way, you won’t have one index file that is a mile long, and I won’t have to scroll through many lines of coding I don’t need to get to a section I need to edit.
If you use the coding exactly as I have pasted it above in the text box, you will have to change your navigation bar URLs to the following:
- About: index.php?about
- Rules: index.php?rules
- Join: index.php?join
- Codes: index.php?codes
- Members: index.php?members
- Extra: index.php?extra