Skip to content

Instantly share code, notes, and snippets.

@okofish
Last active August 29, 2015 14:25
Show Gist options
  • Save okofish/e4071dbe2d075b66ade5 to your computer and use it in GitHub Desktop.
Save okofish/e4071dbe2d075b66ade5 to your computer and use it in GitHub Desktop.
Geek Code age auto-updater
RewriteEngine on
RewriteBase /
RewriteRule ^geekcode.txt geekcode.php [L] # geek code
# people usually place their Geek Code in a txt file, so this silently redirects geekcode.txt to geekcode.php.
# if you already have RewriteEngine and RewriteBase set in your .htaccess, just place the RewriteRule directly below them.
<?php
header('Content-type: text/plain');
date_default_timezone_set('America/New_York'); // for all intents and purposes you don't need this, but PHP throws a nasty warning if it's not included
// for the record I don't know PHP. I stole most of this from http://stackoverflow.com/a/3776843 and winged the rest
//date in mm/dd/yyyy format; or it can be in other formats as well
$birthDate = '04/18/2001'; // set your birthdate here
//explode the date to get month, day and year
$birthDate = explode('/', $birthDate);
//get age from date or birthdate
$age = (date('md', date('U', mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date('md')
? ((date('Y') - $birthDate[2]) - 1)
: (date('Y') - $birthDate[2]));
if ($age <= 9) {
$gcage = '-----';
} elseif ($age >= 10 && $age <= 14) {
$gcage = '----';
} elseif ($age >= 15 && $age <= 19) {
$gcage = '---';
} elseif ($age >= 20 && $age <= 24) {
$gcage = '--';
} elseif ($age >= 25 && $age <= 29) {
$gcage = '-';
} elseif ($age >= 30 && $age <= 39) {
$gcage = '';
} elseif ($age >= 40 && $age <= 49) {
$gcage = '+';
} elseif ($age >= 50 && $age <= 59) {
$gcage = '++';
} elseif ($age >= 60) {
$gcage = '+++';
} else {
$gcage = '?'; // immortal
}
?>
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
your geek code here, but replace a---- or whatever with a<?php echo $gcage ?>
------END GEEK CODE BLOCK------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment