Category Archives: Web Tools

Automatically convert to and from Base64

I just finished a small, simple, yet interesting script for detecting whether code is base64 and encoding or decoding it based on the result. Let's be honest, PHP made it super easy for me with the base64_encode() and base64_decode() functions. I just wrapped it up in what I think is a pretty handy little tool that I know at least one person will get some use out of!

Try it out: Base64 Converter

[ad]

View HTTP Response Headers

Just a quick note to share a site I found that comes in handy when needing to debug web troubles. You can use the site to handily view HTTP request and HTTP response headers to see exactly what's going on behind the scenes.

Web Sniffer

To be totally honest, I’ll probably end up creating my own site for this because I like to build things out for the fun of it.

[ad]

How to view where DNS has propagated all over the world

I just wanted to quickly share a nice tool that I use all of the time when transferring sites to different servers or just changing DNS entries. Sometimes it's hard to tell how long or if the DNS for your domain has updated in other regions in the world. In this case, I use WhatsMyDns.net. It's a neat tool that allows you to look up the current DNS listing for common entries (I really only ever need to use A or CNAME) in quite a few servers located around the world. Since DNS propagates differently by geographic region, this tool is a very good overview as to how users are accessing your site.

Also, if you're like me and constantly need to check your IP address and don't want to always search google for "whats is my ip", I'd recommend you bookmark whats my info, a simple, non-bloated site that gives you what just you're looking for.

[ad]

PHP File-System Cache

[ad]

I’m just sharing a couple of functions I created a while back to cache some resource-intensive processed dada for quick and easy access. This is pretty ideal for large amounts of data and it’s very simple to set up. The beauty of this is that you can store just about any data type – it doesn’t have to be a string.

Just setup the cache directory to have proper read/write permissions (preferably in a non-accessible from web directory). Then use the two functions.

Example usage:

1
2
3
4
5
6
7
8
9
// The 2nd argument, $hours is how long to retain data before getting new
$contents = get_cache('TEST_KEY', 24);
if ($contents === false) {
	// This is where you'd get data from an API, DB or whatever
	$contents = 'Just some example contents';
	set_cache('TEST_KEY', $contents);
}
echo $contents;
}

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
define('CACHE_DIR', 'cache/'); // Include trailing slash
 
function get_cache($key, $hours) {
	$file = CACHE_DIR . md5($key) . '.cache';
	if (!file_exists($file) || filemtime($file) < time() - $hours * 3600)
		return false;
	return unserialize(file_get_contents($file));
}
 
function set_cache($key, $value) {
	$file = CACHE_DIR . md5($key) . '.cache';
	file_put_contents($file, serialize($value));
}