PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP One File Website
Your Ad Here

One File Website


One File WebsiteThis 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?



Author's URL: allsyntax.com
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Add comments to "One File Website"

Only registered users can write comment

No comments yet...