« Bollywood happy at Sanjay Dutt’s bail
What would you do in your last 60 minutes? »


Dec
12

One File Website

Posted by Asim

Making a website and then managing it is really a tough job, ever thought of a one file website… well i guess that this wont be tougher for anyone. So all newbie’s who always wanted to have a website, but not the hassle of managing this is all for you. Well starting from the start you need a have little bit of PHPing knowledge and somewhat logical thinking :P. This will be for the smaller websites, for the larger ones you can always include, this is still a great tutorial. It’s quite simple really, PHP has a nice variable array called $_GET, You can set a variable to be equal to this, to use in if statements, like this:

  • First Step

<?php 
$page = $_GET['page']; // Gets ‘page’ eg: index.php?page=
if (($page == ‘news’) or ($page == ”));
{  // All this does is output if the page is equal to news
?>
This is the content of the news

<?
}
elseif (#page == ‘other’)
{ // Just another page
?>

<?
}
?>

  • This basically does what it looks like, you click the go home link and you get taken back to the news page. You can also do something like this, if you want a header and footer (all these files can be included instead of all on one page, if you want)

<?php 
echo(”<html><head><title>Page Title</title></head>”); //like this
$page = $_GET['page']; // Gets ‘page’ eg: index.php?page=
if (($page == ‘news’) or ($page == ”));
{  // All this does is output if the page is equal to news
?>

  • This is the content of the news

<?
}
elseif (#page == ‘other’)
{ // Just another page
?>

This is the other page <a href=”index.php?page=news” mce_href=”index.php?page=news”>Go home</a><?
}
echo(”</body></html>”); // and this
?>

  • So there it is, very simple, short, and satisfying tutorial on how to build an entire website with one file.

Keep in mind, you can keep adding elseif statements if you want, but also remember, the more content on one file, the longer the loading time… It may be a good idea for larger sites to include their files in the if and elseif statements.. and to require a file for the header and footer. If you want a different title per page, just use a variable and teh same get array, if the page is equal to whatever, then the variable $title = whatever… Get it?
If not just e-mail me… :)

Start Slide Show with PicLens Lite PicLens

One Response to “One File Website”

  1. 1
    Abhishek Says:

    you can do that or use switch for assigning the content to a variable and then displaying the variable at a desired place:

Leave a Reply