20
2013
Simple session based “flash” messages
Quite a while ago, I grew tired of trying to come up with new and creative ways to display simple, one-time messages to users without crazy amounts of code for something that was frequently as trivial as “Saved!”. Sessions are the obvious solution, however, without a single function that could both generate, AND display the messages, it still wasn’t any better. And as usual, where there’s a will, and some code- there’s a way! Before […]
18
2013
Custom PHP MySQLi Database Class
Updated class files (documentation remains the same) with better error handling and full OOP class structure can be found here. Since the depreciation of the mysql functions in PHP (archive here), I thought it may be handy to more effectively future-proof my web applications by wrapping my database interactivity functions in a class (and oh how it is!), and as I was building a new web framework anyway- I figured why not! Unrelated: featured image […]
4
2013
Using PHP to output images (AWESOME STYLE)
Don’t get me wrong, I’m not lazy, but I’m also NOT a front end designer or HTML guru. So when it comes to repeating tasks endlessly that are even mildly lengthy- I get bored. That’s right, I said it- b.o.r.e.d. Tonight was a perfect example! As a back end engineer, I’m nearly always provided very tidy, but elaborate HTML assets, which are then on my desk to become amazing and highly functional beings. But after […]
13
2011
Using PHP to merge and minify CSS and Javascript
And yet another ‘bangin’ update! Don’t use this (I’m going to leave it here for reference), use the magicmin javascript and css minification/caching class instead for performance, better javascript minification, caching, gzip, base64_encoded images, and more! One MAJOR factor in the usability of your website is site load time. This is affected by a number of factors: the number of images, database queries, and the number of server requests to fetch your stylesheets and javascript […]
25
2011
Using PHP to Replace Special Characters with their Equivalents
After having just completed an extensive text file parsing script, I discovered something very very very annoying. A small army of Microsoft Word inspired characters had invaded the imported plain text files (courtesy a number of citation management softwares and websites), causing text to have all sorts of ‘fun’ symbols sprucing things up. For example “Tâ��ms” => “Teams”, but with that extra something added in for visual highlight (or something). So what was a programmer […]
1
2011
Data Encryption Using AES_ENCRYPT
Having databases contain information on subscribers, customers, clients, and the like is similar to playing russian roulette. You’re never certain as to when the bullet comes! Same principles apply to having your customer’s sensitive information yanked from your precious databases! We all watch the news to see which company will have their customer details compromised next. Most recently, Sony has now had approximately 100 million accounts compromised, costing them upwards of $171 million dollars. And […]
21
2011
Simple (Advanced) Click Tracking Using PHP and MySQL
On a recent project, I was asked to record the pages that each user was navigating to in a secured special-purpose website. Initially it seemed daunting, however I recalled a script I’d written to track email open rates using PHP. I am generally disinterested in maintaining a database table of pages, along with a second table of clicked links as I find it to be very inefficient, so I opted to create a simple pass-through […]
18
2011
Exploding a String using Multiple Delimiters Using PHP
Updated February 12th, 2013 to reflect Dave’s comment function below- A++ for simplicity! function explodeX( $delimiters, $string ) { return explode( chr( 1 ), str_replace( $delimiters, chr( 1 ), $string ) ); } $list = ‘Thing 1&Thing 2,Thing 3|Thing 4’; $exploded = explodeX( array(‘&’, ‘,’, ‘|’ ), $list ); echo ‘<pre>’; print_r($exploded); echo ‘</pre>’; Earlier today, I was looking for a simple function to explode text that was contained in string format to be output […]
16
2011
Helpful MySQL Query Functions and Tips
In case you’re wondering, I don’t just spend a couple hours a week throwing random bits of code onto this blog- I spend anywhere between 60- 100 hours per week making code my bitch. But thousands of hours and millions of lines of code later, I’m still occasionally stuck trying to remember a query (but then again when you’ve got most of the MySQL manual embedded in your brain, the info becomes hard to sort […]
29
2011
Get Location From User IP Address
For many of the websites that I work with and manage, IP addresses are collected; primarily as a means to combat spammers, secondarily because it’s always interesting to
Recent Snippets
- htaccess : Only allow access to specific wordpress upload types if logged in
- MySQL : Query WordPress Database for Invalid Media Filenames
- PHP : Get Actual IP Address with PHP
- JavaScript : Allow Tab in Textarea
- PHP : Clean sanitized database contents on output
- htaccess : Force www. prefix in URIs
- PHP : Force File Download with Correct Content Type
- Wordpress : Disable upgrade notification