Yesterday I spent the day keeping myself busy with my blog supplement pages. I'm finally taking the time to learn php. I'm re-writing all my non-blog pages in php. The great thing about that is if I want to change something in the sidebar or whatever, I don't have to go through and make that same change over and over in the html code for each individual page. I'll change it once in the main php code, and it will take effect on every page.
The actual blog is hosted by Blogger, and thus will be unaffected by all of this.
Basically, I'm using the require() function to paste in all the code that is the same on every page; things like the sidebar and footer. It reduced the actual .html files for the web pages down to the content that is unique to that page. As an example, my template page that I use to create new pages was 200 lines (before actual content is added), now it is 31 lines.
None of the web addresses or file names are going to change, though. You'll notice they still have their .html extension. In fact, the files themselves are still .html files. I just told it to run .html as a php file with a little .htaccess magic:AddType application/x-httpd-php .php .htm .html
AddHandler x-httpd-php .php .htm .html
Also, the non-www version of my web address finally 301 redirects to http://www.mastermarf.com, as I've wanted it to all along.
I'm sure there's so many neat things I could do with php, I'm just beginning.
Tuesday, December 23, 2008
«Learning PHP»
Subscribe to:
Post Comments (Atom)
Label Cloud
About Me
Alaska
Animals
Anonymous
Art
Atheism
Bicycle
Blog Reactions
Blog Upgrades
Blogger
Blunt Honesty
Buildings
Caturday
Clothing
Code
Comics
Computers
Copyright
Cruise Ship Watch
Death
Desktop Backgrounds
Disasters
Doomsday
Economy
eMail
Emergency
Energy
Flying Spaghetti Monster
Food
Free Speech
Friends
Games
Gay Rights
Google
Goth
Holidays
Idaho
Idle Mind
Illness
Injury
Internet
Japan
Jury Duty
Ketchikan
Large Hadron Collider
Lasers
Law
Lies
Magic: the Gathering
Master Marf
Meme
Milestones
Money
Motivational Monday
Mountain
Mountain Dew
Music
Musical Taste
Photos
Poems
Politics
Polls
Pony
Power Outage
Problems
PSAs
Random
Reader Opinion
Reader Submission
Relationships
Religion
Scam
Science
Science Fiction
Scientology
Screenshots
Sea-Monkeys
Ships
Sims 3 Legacy
Social Norms
Software
South Park
Space
Stupidity
Technology
The Game
Tourism
Trail
Unusual Ads
Vacation
Weapons
Weather
Web Feeds
Word Play
Work
YouTube
I use the same approach on one of my sites and essentially what you end up with is your own template for your web pages with the major elements ( eg header sections, sideebare sections) pulled through as server side includes.
ReplyDeleteI have used the include function for this and thought this was better because errors dont stop script execution. However on reflection I think you may be right in using require as perhaps an error should stop execution - until it gets fixed. Any thoughts?
@ Bunc: Yeah, that's what I figured after I read about the difference between the two. If there's an error, whatever comes after it is going to be corrupt and not display right anyway. No need to waste any more resources and CPU cycles on it.
ReplyDeleteI think that your certainly right when it comes to "scripted" elements of a website. Any error could have repercussions further in the script and it's probably better to stop this happening. I am not so decided about server side includes though where this is simply being used to , for example, include a header or sidebar element which might largely be text or images etc.
ReplyDeleteIn such a situation I might want the page to continue loading with the rest of the elements whihc are not causing an error. At least the visitor would see the remainder of the page.
It's probably academic though in that kind of situation because errors are unikely where the include is only of standard text, links etc etc.
Require is defo better for including script elements but I am undecided for more bog standard includes. On balance I think I might change to using require though.
@ Bunc: Well, how I have mine set up for example, if the first script were to fail to load there would be no html header and the browser wouldn't even know what type of file is being served to it.
ReplyDeleteAlso, the html below would be malformed. It would chose the wrong ending tags for very important div tags. Nothing would match up.