Websites are wonderful for giving the user information about your product or service. Sometimes the amount of pages are staggering, and updating many pages takes time. PHP is great for websites that have dynamic content. In this day and age, using multiple HTML files is too much hassle when making a subtle change. In this example, you will setup a website that appears to do everything inside index.php (even though includes are performing the work). This is a good way to navigate your site using only one GET variable. We will be using 4 files in this example, altho it can be expanded upon very easily.
How it all works
When the request to index.php is made, PHP will first check the url to see if the variable "a" has been set (e.g. ?a=home). It will check this value against the keys of the $pages array, if the key is found inside the array, the value of the array (the filename) is passed to the include function and loaded. In the case that the variable is non-existing or a 'bad value' the default page ($default_page) will be loaded. The header.inc and footer.inc files will automatically be inserted before and after the content page respectively.
Required Files
These files are included, not linked to. Your users will never know these files exist, unless you have an error message dump it out somewhere.
(error.inc and style.css are not required for this example)
index.php - this is the daddy script that determines what to do
includes/header.inc - this file will contain everything from the doctype to the end of the header/nav system.
includes/footer.inc - this file will contain everything from copyright to the final </html> tag.
includes/main.inc - this file will contain the middle part that has all the content.
includes/aboutus.inc - this file will contain the middle part dealing with the about us page.
includes/error.inc - (optional) this file will contain the middle part dealing with the about us page.
style.css - (optional) this is where your styles will go, should you seperate them from header.inc
Lets look at the files:
index.php
<?php
/*
What this does:
This script will load a header, content, and a footer for output to the browser.
The content file is loaded based on the value of $_GET["a"].
This script will double check to ensure that the keyword is valid, otherwise it uses a default.
No complicated if or switch statements are used, this is where the $pages array comes in.
Breakdown:
$cur_page will be populated from $_GET["a"] (the keyword), eg: index.php?a=home or index.php?a=
$pages contains an array of 'keys' (for ?a=) and 'filenames' (in includes/) to valid pages that can be accessed.
If the keyword doesn't exist, $default_page will be loaded instead. (this can be modded to use an extra error.inc file)
The include file is loaded.
*/
unset($pages);
$pages[""] = "main.inc";
$pages["home"] = "main.inc"; //setup home as well
$pages["about"] = "aboutus.inc";
//add more pages here!
$cur_page = $_GET["a"];
$default_page = ""; //this needs to be a valid key from $pages
$inc_path = "includes/";
//lets include our header
include $inc_path . "header.inc";
if ($pages[$cur_page]){
//lets include the correct file
include $inc_path . $pages[$cur_page];
}else{
//the keywords didn't match anything so lets load $default_page
include $inc_path . $pages[$default_page];
//OR you could have another file error.inc loaded
//include $inc_path . "error.inc"; //include a custom error handler
}
//lets include our footer
include $inc_path . "footer.inc";
?>
includes/header.inc
<html>
<head>
<title>This is an example site</title>
<style type="text/css">
.copyright {font-size: 10px; text-align: center}
</style>
</head>
<body>
<h1>Example Site</h1>
includes/footer.inc
<span class="copyright">© 2007 my website. all rights reserved</span>
</body>
</html>
includes/main.inc
<h2>Welcome to Main!</h2>
<p>This is an example of what could go on the main page!</p>
includes/aboutus.inc
<h2>About Us</h2>
<p>Here you can find all about us!</p>
includes/error.inc (If you uncomment the error code)
<h2>Error</h2>
<p>There was an error found!</p>
Thats it! Copy the files to your php webserver, be sure the paths are correct and the files are in the proper places. Also, links should start with: "index.php?a=KEYWORD&more=vars"... etc etc (or just: ?a=KEYWORD&more=vars if its' your index.php file :P )
Testing
To test your page, navigate to these urls: (home should load when trying a bad keyword)
index.php?a=
index.php?a=home
index.php?a=about
index.php?a=badkeyword
Monday, January 08, 2007
Wednesday, December 27, 2006
Programmers have dirty mouths...
I've been poking around on Google Code Search a bit and have pulled a few funny queries.
Bitch – 15,400 results. "$bitch" pulls up 50 results.
Shit – 47,300 results. "$shit" pulls up 100 results.
Fuck – 36,400 results. "$fuck" pulls up 100 results.
Ass – 10,800,000 results. "$ass" pulls up 17,600 results.
i hate ff/firefox – 0 results
i hate ie – 20 results
i want to die – 50 results
i will kill you – 100 results
kill myself – 300 results
fuck yourself – 3,000 results
funny comments
Bitch – 15,400 results. "$bitch" pulls up 50 results.
Shit – 47,300 results. "$shit" pulls up 100 results.
Fuck – 36,400 results. "$fuck" pulls up 100 results.
Ass – 10,800,000 results. "$ass" pulls up 17,600 results.
i hate ff/firefox – 0 results
i hate ie – 20 results
i want to die – 50 results
i will kill you – 100 results
kill myself – 300 results
fuck yourself – 3,000 results
funny comments
- ...I fucking hate you, you monopolizing piece of Netscape feces. */
- /// @note we fucking hate itunes for taking over podcasts and inserting
/// their own attributes. - /* I fucking hate dealing with strings in C. */
- # I FUCKING HATE YOU WINDOWS AND YOUR FUCKING FILENAMES, GO TO HELL
if "\\" in name: name = name.replace("\\", "/") - /* I FUCKING HATE NICKSERV!!!!!! */
- # Fucking windows!
- return NULL; /* STUPID FUCKING WINDOWS COMPILER WON'T SHUT UP */
- // are you crazy? o_O, no fucking windows directory? o_O
- /* Fucking windows ass-shit. */
- * client/src/memcache.c: Fucking Linux/GPL/gcc, why can't it just curl up and die?
- /* I hate fucking Unix. This shit drives me nuts. Oh, and while we're at
* it, what the HEMHORRAGING FUCK is with sun_path being 180 bytes (!?) and
* that not being #defined anywhere? Fuck me with a ladder. */ - /* RFC1035 SUCKS ASS! */
- /* Holy shit! Quick, put everything back! */
- // sometimes I Hate Mozilla... ;-(
- /* I hate to include an include inside an include (ha!) however, I don't */
- # we could call the root "My Computer" and mess with get_contents()
# to return "A:", "B:", "C:", ... etc. as it's children, but that
# would just be terminally cute and I'd have to shoot myself - Error("no consoles found in configuration file");
kill(thepid, SIGTERM); /* shoot myself in the head */
return; - # This is where most people should stop reading.
Monday, October 02, 2006
Why I hate developing for idiots...
In this day and age, technology is all around us, from cars to watches, to cell phones to the Internet. The Internet is an infinitely growing hard drive with infinite amounts of knowledge, communication, and people dancing on treadmills. It boggles my mind when I hear people describe the web as some overly hyped-up fad. The web is obviously much more than a 'fad' with all the search engine services processing and categorizing everything. 10 years ago the www was tiny compared to what it is today and couldn't do half of what it can. Websites and the capabilities of what they can do double daily. The internet is not going anywhere anytime no matter how hard you close your eyes. You cant escape change.
That brings me to my next point, people who don't understand the technology, data or www potential because they wont research it for themselves. Don't get me wrong, lots of people research lots of things and are very active online. I'm talking about a different breed of idiots unlike you or me. The kind of people who want buttons everywhere instead of links. The people who use bright yellow 24pt Aral black bold italic underline on a white background whenever they have the opportunity to edit text on a 12pt layout. The people who think the layouts color or position can be radically altered with just a click of a mouse like in 'word.' The people who want the spinning email gif that always has a wrong jagged background color. The people who think that whe web can be used to fold the 7TH dimension through the 8TH dimension to the -2ND dimension. Oh, did I also mention the fact that most people expect everything to be easy and a 2-second job?
The web is all about information. With technologies like RSS and ATOM you can force data down users throats. You can keep people very well informed by getting them to use an RSS feeder. I wont even get into what you can do with the power of AJAX apps, just look at gmail. However with these new technologies emerging and people not understanding that they are new, its not hard to believe that some people want the impossible and think that because google literally does it overnight, you can do it overnight despite the month of actual work the project might need. People think that when you develop something, no matter how complicated, it shouldn't of taken as long as it took you. Here's my philosophy on programming: If it's easy to make, it's difficult to use. If it's easy to use, it's difficult to make. Why is this so hard for people to grasp?
That brings me to my next point, people who don't understand the technology, data or www potential because they wont research it for themselves. Don't get me wrong, lots of people research lots of things and are very active online. I'm talking about a different breed of idiots unlike you or me. The kind of people who want buttons everywhere instead of links. The people who use bright yellow 24pt Aral black bold italic underline on a white background whenever they have the opportunity to edit text on a 12pt layout. The people who think the layouts color or position can be radically altered with just a click of a mouse like in 'word.' The people who want the spinning email gif that always has a wrong jagged background color. The people who think that whe web can be used to fold the 7TH dimension through the 8TH dimension to the -2ND dimension. Oh, did I also mention the fact that most people expect everything to be easy and a 2-second job?
The web is all about information. With technologies like RSS and ATOM you can force data down users throats. You can keep people very well informed by getting them to use an RSS feeder. I wont even get into what you can do with the power of AJAX apps, just look at gmail. However with these new technologies emerging and people not understanding that they are new, its not hard to believe that some people want the impossible and think that because google literally does it overnight, you can do it overnight despite the month of actual work the project might need. People think that when you develop something, no matter how complicated, it shouldn't of taken as long as it took you. Here's my philosophy on programming: If it's easy to make, it's difficult to use. If it's easy to use, it's difficult to make. Why is this so hard for people to grasp?
Friday, August 18, 2006
Digg Bugg - Dup permalinks?
I found a digg bugg today when I accidentally submitted an article twice via a dbl-click. It seems that the articles are given a unique key, however, the title doesn't seem to be checked for a duplicates when submitting. This allowed two articles with the exact same permalink.
The link given to the articles is here.
When following the link, one of the two seems to be randomly chosen for display (try F5 a few times). They have their own comments and own digg value. Without being able to delete something like this, it can cause confusion and server problems as the wrong one might be getting dugg, burried or commented on. I notified digg of the problem and hope it gets resolved.
In my submitted list, you can see the two diggs that i've marked dups.
http://digg.com/users/da404lewzer/submitted
The link given to the articles is here.
When following the link, one of the two seems to be randomly chosen for display (try F5 a few times). They have their own comments and own digg value. Without being able to delete something like this, it can cause confusion and server problems as the wrong one might be getting dugg, burried or commented on. I notified digg of the problem and hope it gets resolved.
In my submitted list, you can see the two diggs that i've marked dups.
http://digg.com/users/da404lewzer/submitted
Thursday, August 17, 2006
Not the best month for AOL...
Aug 3rd, AOL announces they will be laying off 5,000 of the 19,000 people working for them.
Aug 7th, AOL releases 3 months and 650,000 users worth of search queries. The New York Times has identified one of these anonymous people from one of the many sites that have the data available.
Aug 15th, AOL was caught spamming articles on Digg.com. They were having employees digg items to get ratings. (Maybe why they are getting fired? lol)
Aug 16th, AOL says a convicted spammer may of hidden half a million dollars in gold and platinum on his parents' property. Tonka Time.
hrm. 2 weeks left in august. lets see what happens.
http://money.cnn.com/2006/08/03/technology/aol_layoff.reut/
http://www.ugcs.caltech.edu/~dangelo/aol-search-query-logs/
http://data.aolsearchlogs.com/
http://www.splunkd.com/
http://diggforlife.blogspot.com/2006/08/aol-busted-for-spamming-digg.html
http://www.msnbc.msn.com/id/14365934/
Aug 7th, AOL releases 3 months and 650,000 users worth of search queries. The New York Times has identified one of these anonymous people from one of the many sites that have the data available.
Aug 15th, AOL was caught spamming articles on Digg.com. They were having employees digg items to get ratings. (Maybe why they are getting fired? lol)
Aug 16th, AOL says a convicted spammer may of hidden half a million dollars in gold and platinum on his parents' property. Tonka Time.
hrm. 2 weeks left in august. lets see what happens.
http://money.cnn.com/2006/08/03/technology/aol_layoff.reut/
http://www.ugcs.caltech.edu/~dangelo/aol-search-query-logs/
http://data.aolsearchlogs.com/
http://www.splunkd.com/
http://diggforlife.blogspot.com/2006/08/aol-busted-for-spamming-digg.html
http://www.msnbc.msn.com/id/14365934/
Tuesday, July 25, 2006
Google Maps Beta
It's been too damn long since i've posted something, so to kick things off, ya gotta love the power of Google! Google Maps for Mobile launched today in Beta status.
Here's the scoop: Real-time traffic estimates & directions, check traffic conditions and one-touch favorites.
Wait! What about aerial shots!? No problems, it includes the awesome satellite images that we all love to stare at for hours.
Google really said it best, it's the new hotness!
Here's the scoop: Real-time traffic estimates & directions, check traffic conditions and one-touch favorites.
Wait! What about aerial shots!? No problems, it includes the awesome satellite images that we all love to stare at for hours.
Google really said it best, it's the new hotness!
Friday, November 04, 2005
SSo what?
Friday, October 21, 2005
Subscribe to:
Posts (Atom)
