» Drawing Frames
» Things & Places
» Fun facts
» Prank Calls
» Episode List
» Episode Ratings
» Homer's Mmmm...
» Things & Places
» Filled Requests
Drawing Frames: 185
|PHP include tutorial
This tutorial was written for people with no experience at all in PHP. PHP is a very versatile and potent language, so we'll only be scratching the surface in this tutorial.
But don't worry, knowing these two littles codes will save you hours of boring work. No more updating 50 pages when you add a link!
Step 1 (finding if your host supports PHP)
First, you have to make sure your host supports PHP. If it does not (many free hosts do NOT support PHP), your magical journey stops here...
To see if your host supports PHP, type <?php phpinfo(); ?> in notepad. Save the file as info.php (make sure to change the extension) and upload it to your server. If, when you visit http://yoursite.com/info.php, you see a page like this one, your server supports PHP. You can move on to step 2.
If you don't have access to a PHP-enabled host, you can still try it out on your computer. Just install a webserver (like Apache or Xitami) and get the PHP installer from php.net.
Step 2 (the include code)
Second, you will have to insert this code on the main page of your website, the one with the layout/design. Where you put this code is where the content will appear. It might be a good idea to put this into a table or cell so that you can control the width.
include ($_GET['jump']. '.php');
Don't forget to rename your main page (index.html) to index.php for this to work. You will also have to rename all your content files to .php (if you don't change the .php to .html in the code above) for this to work.
Step 3 (including other content pages)
To display other pages, you will have to change all your links (on the index.php page). Example:
This tells the browser to get the page.php file and to include it into the index.php page which has the include code. It's important that you do not put an extension in the link. Simple write the name of the page.
You can link to other folders using the folder/page style or to an upper folder using ../ .
You can also include (echo) images. This is very useful if you have many images and don't want to do a HTML document for each one of them.
You can see this script in action in the framegrabs and in the grabpics sections.
Put this code in imagepage.php (you can also add other things to this page, like a "close this page" link or a "Images" header or something like that.)
<img src="<? echo $_GET['pic']; ?>">
You also have to change your image links (example link with a tumbnail)
<a href="imagepage.php?pic=image.jpg"><img src="imagesmall.jpg" border="0"></a>
This tells the browser to get image.jpg and to include it in the imagepage.php page.
That's it for now!
No FAQ's right now... contact me if you are having trouble with this tutorial.