The "One Page" Website.
Josh-
Royal Oak, MI
The "One Page" Website
-- written by Josh
You may notice, that sometimes you see sites using one or two pages, rather then using TONS of pages. This isn't usually what it seems. Sometimes they may be using a simple script, that makes it seem so. If you don't understand what I'm talking about, look at short-medias forums. They use similar forms of it everywhere. I see one right now, http://short-media.com/forum/newthread.php?s=&action=newthread&forumid=27. Instead of having a page named "s", ect, they have a page named newthread.php that has another type of "section" of it, "s". I use this to manage my websites, pretty much. You can also make custom 404 pages, which can sometimes be useful to you. Instead of having to go to each individual page, such as:
You can now only appear to have on file, which may appear as:
Home.php?section=index or Home.php?section=contact.php..
Now to start with the coding of the PHP:
Your index.php file should include the following:
[php]
<?php
if ( @!$section ) {
$section = "home";
}
if ( @$result = include ( "$section" . ".php" ) ) {
} else {
include ("404.php");
}
?>
[/php]
Upon loading of your website, it will say index.php, but will be loading home.php. From linking from page to page, you will only need to use index.php?section=(pagename), no PHP included. You can also include HTML files, ect this way.
However, the most useful part, and mostly main part of this small script, is to have more organization, and the usefulness of custom 404 pages.
Everytime something is entered, other then a file that you have, it will bring up 404.php. You can easily modify it to become 404.html, ect.
For example, lets say you don't have a chat.php file in your folder.
When someone tries to go to index.php?section=chat, rather then loading a regular server or windows 404 error, it will load your 404.php page, ect.
I guess you may not want this code, except for looks, but don't underestimate custom 404 pages. They can be very useful, such as you can include something that will email you when the 404 page is opened. This can be very useful in administrating a website with a large amount of pages.
Hopefully there is someone out here that can make use of this, and I wish them best of luck in doing it.
Your welcome,
Josh.
-- written by Josh
You may notice, that sometimes you see sites using one or two pages, rather then using TONS of pages. This isn't usually what it seems. Sometimes they may be using a simple script, that makes it seem so. If you don't understand what I'm talking about, look at short-medias forums. They use similar forms of it everywhere. I see one right now, http://short-media.com/forum/newthread.php?s=&action=newthread&forumid=27. Instead of having a page named "s", ect, they have a page named newthread.php that has another type of "section" of it, "s". I use this to manage my websites, pretty much. You can also make custom 404 pages, which can sometimes be useful to you. Instead of having to go to each individual page, such as:
- Index.php...
- Contact.php..
- About.php..
- Ect..
You can now only appear to have on file, which may appear as:
Home.php?section=index or Home.php?section=contact.php..
Now to start with the coding of the PHP:
Your index.php file should include the following:
[php]
<?php
if ( @!$section ) {
$section = "home";
}
if ( @$result = include ( "$section" . ".php" ) ) {
} else {
include ("404.php");
}
?>
[/php]
Upon loading of your website, it will say index.php, but will be loading home.php. From linking from page to page, you will only need to use index.php?section=(pagename), no PHP included. You can also include HTML files, ect this way.
However, the most useful part, and mostly main part of this small script, is to have more organization, and the usefulness of custom 404 pages.
Everytime something is entered, other then a file that you have, it will bring up 404.php. You can easily modify it to become 404.html, ect.
For example, lets say you don't have a chat.php file in your folder.
When someone tries to go to index.php?section=chat, rather then loading a regular server or windows 404 error, it will load your 404.php page, ect.
I guess you may not want this code, except for looks, but don't underestimate custom 404 pages. They can be very useful, such as you can include something that will email you when the 404 page is opened. This can be very useful in administrating a website with a large amount of pages.
Hopefully there is someone out here that can make use of this, and I wish them best of luck in doing it.
Your welcome,
Josh.
0
Comments
I am following your guides with great interest. Good man.
[php]
<h1>404 ERROR - FILE/FOLDER NOT FOUND!</h1>
<?php
if ($do != "sendmail") {
?>
<form name="sendmail" action="404.php" method="post">
<font face="Verdana,Arial" size="2">
<input type="hidden" name="do" value="sendmail">
E-Mail: <input type="text" name="email" size="60"><br />
404 error found at: <input type="text" name="subject" size="60"><br />
Comments:<br /><textarea name="comments" rows="10" cols="30"></textarea><br />
<input type="submit" value="submit">
</font>
</form>
<?php
} elseif ($do == "sendmail") {
mail("admin@yoursite.com",$subject,$email,$comments) or die("Error: the message could not be sent");
} // endif
?>
[/php]
Will allow the user to send you email about where the 404 was found, ect.
Thanks. It makes me proud to see that I'm being appreciated
Hopefully more tutorials (guides) to come:D
-- Josh
404.php could be changed to echo the url of the page, I suppose. But 404.php is more simple, and just as efficient.
[PHP]$section = $_REQUEST["section"];[/PHP]
GLOABLS in PHP 4 are off:
Good work Josh :thumbup
I wouldn't want anyone to get frustrated, then pissed off at me.
Thanks for the correction,
--Josh
Do any of you have any requests? Maybe I can write it up. :/
[php]
switch ($action) {
case "add":
add();
showForm();
showTable();
break;
case "delete":
delete();
showForm();
showTable();
break;
case "edit":
edit();
break;
default:
showForm();
showTable();
}
[/php]
$action is just $_REQUEST. So using the case switch and some basic functions I can reuse a good chunk of my code. Good stuff, Josh. Keep it coming.
Here is what I have so far... copied most of what is in this thread for the sake of just getting it to work.... I have another page, but I don't know where to add it, or how to set it's "section". I'm all around a bit lost, but I understand the jist of it I think.
[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Christopher Sklenarik" />
<meta name="keywords" content="3d, modeling, designer, vector, raster, art, tutorials, editorials" />
<meta name="description" content="The Portfolio of Christopher Sklenarik" />
<meta name="robots" content="all" />
<title>Fusion Digital Media - The Art of Christopher Sklenarik</title>
<!--
//For future CSS Style when graphics and final design is ready.
<style type="text/css" title="currentStyle" media="screen">
@import "/001/001.css";
</style>
//For future use of an Icon when graphics and final design is ready.
<link rel="Shortcut Icon" type="none/no-icon" href="http://www.fusion-dm.net/no-icon.ico" />
-->
<?php
if ( @!$section ) {
$section = "home";
}
if ( @$result = include ( "$section" . ".php" ) ) {
} else {
include ("404.php");
}
?>
</head>
<body>
<h1>404 ERROR - FILE/FOLDER NOT FOUND!</h1>
<?php
if ($do != "sendmail") {
?>
<form name="sendmail" action="404.php" method="post">
<font face="Verdana,Arial" size="2">
<input type="hidden" name="do" value="sendmail">
E-Mail: <input type="text" name="email" size="60">
404 error found at: <input type="text" name="subject" size="60">
Comments:<textarea name="comments" rows="10" cols="30"></textarea>
<input type="submit" value="submit">
</font>
</form>
<?php
} elseif ($do == "sendmail") {
mail("me@mysite.net",$subject,$email,$comments) or die("Error: the message could not be sent");
} // endif
?>
</body>
</html>
[/PHP]
[php]
$section = $_REQUEST;
[/php]
so that $section will have a value.
In the actual HTML you'll need:
[php]
<input type="hidden" name="section" value="put_the_value_here" />
[/php]
You can change the value of 'section' by (assuming the form name is mainForm):
[php]
document.mainForm.section.value = 'new Value';
[/php]