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:
|
<?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="/img_articles/5899/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?





