| Subcribe via RSS

A Myth

August 22nd, 2008 | No Comments | Posted in Life

We had to write Native American myths in my literature class. Here is mine (I got a 98% on it).

More »

Tags:

The 16 worst things in the universe

August 19th, 2008 | 1 Comment | Posted in Life, Rants

A very random list, not in any order (except the first one). Don’t take offense if you like one of the things on this list (or if you ARE on this list).

  • Windows Vista
  • People that sign up for my site and never post anything
  • Spambots on my blog (my blog sends me an email when someone posts a comment, so it’s annoying) (when I get un-lazy I’ll install a spam filter)
  • People who I used to work with that start a new site, without telling me anything about it (you know who you are)
  • Heavy textbooks
  • Internet that doesn’t work half the time after your ISP is bought by a big company who moves the data center from Georgia to Ohio/New York/Chicago
  • AP US History
  • Internet Explorer (!!!)
  • People who take my code for a game, then make a new game based on my code which gets more popular than mine, without giving me any credit
  • Cybersquatters
  • Having to clean up after my dog after he gets in the trash can
  • Having to clean up after my dog when he throws up on the floor
  • Being kept awake past midnight by my dog when he scratches at the door due to a thunderstorm
  • Having a dog (jk!)
  • Boring classes (last year 1/2 of my classes would literally have no work on some days, it’s better this year…)
  • People who read an interesting blog post on my site and don’t leave a comment (hint hint hint)
Tags:

How To Catch Hackers, Pt. 2a

August 18th, 2008 | No Comments | Posted in Life, Site News

As a minor update, this is what my inbox looks like since adding the SQL/XSS detector code:

Update: This was supposed to be part 2a…

Tags:

New Computer Pics

July 11th, 2008 | 6 Comments | Posted in Computers, Life

I finished building my new PC yesterday. It’s very nice! Here are some photos.

New PC

New Computer On The Way

July 7th, 2008 | No Comments | Posted in Life

I’ve been wanting a new computer for a while, and I finally ordered the parts yesterday! This is what I’m getting.

CPU: AMD Athlon 64 X2 4800+ Brisbane 2.5GHz 2 x 512KB L2 Cache Socket AM2 65W Dual-Core Processor
Memory: G.SKILL 2GB 240-Pin DDR2 SDRAM DDR2 800 (PC2 6400) Desktop Memory
Hard Drive: Western Digital Caviar SE WD1600AAJS 160GB 7200 RPM 8MB Cache SATA 3.0Gb/s Hard
Video Card: Diablotek Nvidia Geforce 6200 128mb (already have)

I’ll photoblog the assembly when I get the parts.

Tags:

Introduction to Templating with PHP

July 6th, 2008 | 7 Comments | Posted in Articles, Life, PHP

Templating is important to nearly every website now. It allows you to use the same
design on all your pages, while having different content. There are many ways of
doing it; this article will focus on the most common

Method 1: File Inclusion

Read the paragraph below before using this code!

[header code]
<?php
include($_GET['file']);
?>
[footer code]

This is the most simple templating system. Pages are accessed by going to the
URL

http://domain.com/index.php?file=aboutus.php

, etc. However, you should
not use this code. Why? People could use a URL such as

http://domain.com/index.php?file=/etc/passwd

or even

http://domain.com/index.php?file=http:/ … ngtool.php

, and
include any file they want from your server or elsewhere.

One way to prevent hacking with this method is to create a file list, and
prevent files other than those in the list from being accessed.

[header code]
<?php
$allowed = array('aboutus.php', 'products.php', 'home.php', 'contact.php');
if(in_array($_GET['file'], $allowed))
include($_GET['file']);
else
die('You are not allowed to access that file!')
?>
[footer code]

Method 2: Single File

In this method, all the pages are stored in one PHP file.

[header code]
<?php
$pages = array(
'aboutus' > '
Page contents 1
',
'products' > '
Page contents 2
',
'home' > '
Page contents 3
',
'contact' > '
Page contents 4
'
);
if(in_array($_GET['page'], $pages))
echo $pages[$_GET['page']];
else
echo 'The page you tried to access does not exist.';
?>
[footer code]

This can be easier to edit, because you only need to edit one file, but you also
have to remember to escape your quotes, e.g. don\’t, I\’ve, etc. as the pages
are stored as PHP strings.

Method 3: Content Management System

A content management system is a pre-made PHP script that makes it easy to setup
a website. You can usually download more templates, or make your own, although
it is usually more difficult than if you were making a template system from
scratch. These script also contain many features, called modules or plugins,
that allow you to add new stuff to your site–forum, poll, blog, directory,
store, etc. and you can also download more of these.

Method 4: Template File

Template files contain all the necessary information for a page’s structure and layout,
and placeholders for the content. They need a method of storing the page data as
well. Here is an example of a template file:

My Site - [pagetitle]
[pagetitle]
[pagecontent]

In this example, the data files are stored in separate files, similar to method 1. However,
the files contain a PHP array rather than the page contents.

1<?php
$page = array(
'title' > 'About Us',
'content' > 'This is our about us page!'
);
?>

A PHP script ties it all together.

<?php
$allowed = array('aboutus', 'products', 'home', 'contact');
if(in_array($_GET['file'], $allowed))
include($_GET['file'].'.php');
else
die('You are not allowed to access that file!')
$template = file_get_contents('template.html');
$replace = array('[pagetitle]', '[pagecontent]');
$replacements = array($page['title'], $page['content']);
$template = str_replace($replace, $replacements, $template)
echo $template;
?>

This method is the most flexible, as you can easily add new template variables (the text
in brackets in the above example). There are also PHP templating libraries available,
however these are often hard to use, and you can easily make your own.

Tags: