freestyle developments

site menu

  • Jump to page content
  • home
  • blog
  • about
  • projects
  • contact

blog

Implementation of HTTP Digest Authentication in PHP

2010.07.10

So I could only find one other PHP based HTTP digest auth example on the internet…and it looked as though it might not even work. I wrote an abstract class as a base that allows you to easily build your own implementation.

You’d use it like so:


class MyAuth extends HTTPDigestAuth {
    // Implementation of abstract methods
}

$authenticator = new MyAuth();
$user = $authenticator->authenticate();

if(!$user) {
    die();
}

Read the rest of this entry »

Tags: authentication, digest auth, HTTP, PHP, security
Posted in PHP | No Comments »

blog

Migrating WordPress to a new URL

2010.07.06

WordPress is a nonsense, and stores it’s URL in multiple places in the database. If you want to move your WordPress install to a different host, exec the following MySQL commands to change the URL in all instances:

UPDATE wp_options
   SET option_value = REPLACE(option_value, "[Old site URL]", "[New site URL]")
 WHERE option_value LIKE "%[Old site URL]%";

 UPDATE wp_posts
   SET post_content = REPLACE(post_content, "[Old site URL]", "[New site URL]")
 WHERE post_content LIKE "%[Old site URL]%";

  UPDATE wp_posts
   SET guid = REPLACE(guid, "[Old site URL]", "[New site URL]")
 WHERE guid LIKE "%[Old site URL]%";

Replace [Old site URL] and [New site URL] appropriately

Tags: database, mysql, url, wordpress
Posted in Blog, SQL | No Comments »

blog

JavaScript Namespace

2010.05.05

I normally put my JavaScript function/classes/other things in namespaces. Namespacing your JavaScript is good, it avoids conflicts between scripts on the page and keeps the global namespace clean. I could go into more detail, but luckily it has been done for me.

Declaring namespaces, and checking they exist before using them is a bit of a pain. You might find yourself doing something like:

if(!window.com) window.com = {};
if(!com.mycompany) com.mycompany = {};
if(!com.mycompany.mypackage) com.mycompany.mypackage = {};

…and then add things to it like:

com.mycompany.mypackage.myfunction = function() { return 138; };

To make things worse, if your webpage includes a different script that uses slightly different namespace, say "com.mycompany.mypackage2" you’ll have to check again that the objects "com" and "com.mycompany" already exist.

The following function allows you to use a namespace, without having to manually go through the throws of checking each "space" exists and creating an empty object for each level.

/**
 * I declare a namespace if it doesn't already exist.
 *
 * @param {String} ns The namespace to create/use
 * @param {Object} parent (Optional) The parent object onto which this namespace will be attached.
 * @return True if the namespace was created successfully.
 * @type Boolean
 */
function namespace(ns, parent) {

	if(!parent) {
		parent = window;
	} else {
		// Parent must be an object
		if(typeof(parent) != 'object') {
			return false;
		}
	}

	var names = ns.split('.');

	if(!names.length) {
		return true;
	}

	var name = names[0];

	if(!parent[name]) {
		parent[name] = {};
	}

	if(names.length > 1) {
		names.shift();
		return namespace(names.join('.'), parent[name]);
	}

	return true;
}

…and is used like so:

namespace('com.mycompany.mypackage');
com.mycompany.mypackage.myfunction = function() { return 138; };

Tags: JavaScript, namespace
Posted in JavaScript | No Comments »

blog

Webalizer GroupAgent config – round 2

2010.02.22

A helpful reader pointer out that Opera has borked it’s user agent string, which unfortunately means that webalizer can no longer distinguish between Opera 9 & Opera 10. It is a bit of a shame, but not something I can do anything about.

I also took out the “Version/4″ detection for Safari, because it is a little stinky – any browser could put “Version/” in their UA string (which happens to be exactly what Opera has done). So here is my updated webalizer GroupAgent config, for use with version 2.01 of webalizer (which is the Debian stable version):

GroupAgent      Firefox/3               Firefox 3
HideAgent       Firefox/3
GroupAgent      Firefox/2               Firefox 2
HideAgent       Firefox/2
GroupAgent      Firefox/1               Firefox 1
HideAgent       Firefox/1
GroupAgent      Firefox                 Firefox
HideAgent       Firefox
GroupAgent      Chrome/4                Chrome 4
HideAgent       Chrome/4
GroupAgent      Chrome/3                Chrome 3
HideAgent       Chrome/3
GroupAgent      Chrome/2                Chrome 2
HideAgent       Chrome/2
GroupAgent      Chrome/1                Chrome 1
HideAgent       Chrome/1
GroupAgent      Chrome/0                Chrome 0
HideAgent       Chrome/0
GroupAgent      Chrome                  Chrome
HideAgent       Chrome
GroupAgent      iPhone                  iPhone
HideAgent       iPhone
GroupAgent      Safari                  Safari
HideAgent       Safari
# Instead of using "Opera/10", Opera stuck with "Opera/9.80" and added "Version/10" to their UA
# string - this means we cannot distinguish between Opera 9 and 10 using this version of webalizer
GroupAgent      Opera/8                 Opera 8
HideAgent       Opera/8
GroupAgent      Opera/7                 Opera 7
HideAgent       Opera/7
GroupAgent      Opera/6                 Opera 6
HideAgent       Opera/6
GroupAgent      Opera/5                 Opera 5
HideAgent       Opera/5
GroupAgent      Opera                   Opera
HideAgent       Opera
# TODO: When Debian finally upgrade webalizer, use "MSIE x"
GroupAgent      8.0                     Internet Explorer 8
HideAgent       8.0
GroupAgent      7.0                     Internet Explorer 7
HideAgent       7.0
GroupAgent      6.0                     Internet Explorer 6
HideAgent       6.0
GroupAgent      MSIE                    Internet Explorer
HideAgent       MSIE

Tags: Browser, Config, GroupAgent, Webalizer
Posted in Hosting | No Comments »

blog

IE7 onclick and :active state

2010.01.27

Curiously, if you add an onclick event to an anchor in IE7, the anchor remains in the CSS :active state regardless of whether the javascript returns true or false. It’ll stay in this state untill you click on another element on the page.

e.g.

<!DOCTYPE html>
<html>
<head>
	<style type="text/css">
		a:active {
			background-color:red;
		}
	</style>
</head>
<body>
	<a href="#" onclick="javascript:return true;">Click me</a>
</body>
</html>

Posted in Grinds My Gears | No Comments »

blog

Webalizer GroupAgent config

2009.12.08

I’ve wanted Webalizer to group the UA strings for the major players in the browser market for a while now, and finally sat down this evening to poke around with things.

I don’t believe in “grouping” everything, because it just means I end up with a massive “grouping” list to maintain, and I just know I won’t be able to do that. So I’m just concentrating on the browsers who hold most market share for the browser demographic my client’s site’s are attracting. Besides, browsers with a small market share (I’m taking like less than a couple of percent here) aren’t really worth grouping.

As a developer, I’m interested in what versions of browsers visitors are using, but not that interested…and not so interested that I want to confuse the clients who are going to view the stats for their site. So I’m grouping by major version number, making sure to define a “catchall” style group for version numbers above/below any of the groups I have defined. This means that any new browsers versions released before I get a chance to update the list are still grouped.

The only problem I ran into was trying to define a GroupAgent string for IE. I wanted to match MSIE 8, MSIE 7, MSIE 6, etc. but unfortunately space characters delimit the GroupAgent string. Which is a bit of a pain. I noticed that the sample config file on the webalizer site used quotes to surround the string and encompass the space, but that didn’t work for me. Perhaps because Debian stable is still using version 2.01.10 from 2002. Gotta love Debian. I’ll revisit if they ever update the package.

Anyway, that means that I’m using just version numbers to group IE. Which isn’t great as we could potentially get some false positives…but hopefully not many as we’re matching all the other big players beforehand.

GroupAgent	Firefox/3		Firefox 3
HideAgent	Firefox/3
GroupAgent	Firefox/2		Firefox 2
HideAgent	Firefox/2
GroupAgent	Firefox/1		Firefox 1
HideAgent	Firefox/1
GroupAgent	Firefox			Firefox
HideAgent	Firefox
GroupAgent	Chrome/4		Chrome 4
HideAgent	Chrome/4
GroupAgent	Chrome/3		Chrome 3
HideAgent	Chrome/3
GroupAgent	Chrome/2		Chrome 2
HideAgent	Chrome/2
GroupAgent	Chrome/1		Chrome 1
HideAgent	Chrome/1
GroupAgent	Chrome/0		Chrome 0
HideAgent	Chrome/0
GroupAgent	Chrome			Chrome
HideAgent	Chrome
GroupAgent	iPhone			iPhone
HideAgent	iPhone
GroupAgent	Version/4		Safari 4
HideAgent	Version/4
GroupAgent	Version/3		Safari 3
HideAgent	Version/3
GroupAgent	Safari			Safari
HideAgent	Safari
GroupAgent	Opera/10		Opera 10
HideAgent	Opera/10
GroupAgent	Opera/9			Opera 9
HideAgent	Opera/9
GroupAgent	Opera/8			Opera 8
HideAgent	Opera/8
GroupAgent	Opera/7			Opera 7
HideAgent	Opera/7
GroupAgent	Opera/6			Opera 6
HideAgent	Opera/6
GroupAgent	Opera/5			Opera 5
HideAgent	Opera/5
GroupAgent	Opera			Opera
HideAgent	Opera
# TODO: When Debian finally upgrade webalizer, use "MSIE x"
GroupAgent	8.0			Internet Explorer 8
HideAgent	8.0
GroupAgent	7.0			Internet Explorer 7
HideAgent	7.0
GroupAgent	6.0			Internet Explorer 6
HideAgent	6.0
GroupAgent	MSIE			Internet Explorer
HideAgent	MSIE

Tags: Browser, Config, GroupAgent, Webalizer
Posted in Hosting | 1 Comment »

blog

MooTools Depender, Safari, etags and 412 Precondition Failed

2009.12.04
/**
* This replaces the default MooTools more Depender.request function to use
* HTTP "get" rather than "post".
*
* When sending requests for files via the depender, I was finding that Safari
* wasn't getting and re-evaluating them the second time I visited the page.
* This was because an etag was sent with each script.
*
* Safari responds to etags properly and adds "If-None-Match" and
* "If-Modified-Since" headers to another request for the same file. This makes
* Apache respond with a 412 status (Precondition Failed) as it should do for
* "post" requests (according to RFC 2616).
*
* Unfortunately Safari doesn't then deal with the 412 as it does with a 304
* (Not Modified). It doesn't grab what it has in the cache and put it in the
* response, it gives you nothing.
*
* For "get" requests, Apache has to respond with a 304, or 200 or whatever, but
* not 412. So we change the request method so we don't have to deal with 412.
*/
Depender.request = function(url, callback){
    new Request.JSON({
        url: url,
        secure: false,
        onSuccess: callback,
        method:'get'
    }).send();
};

Tags: 412, Apache, Cache, Caching, Depender, etag, GET, If-Modified-Since, If-None-Match, MooTools, POST, Precondition Failed, Request, Request.JSON, RFC 2616, Safari
Posted in Grinds My Gears | No Comments »

blog

IE7 and HTTP

2008.12.05

Why doesn’t IE7 assume I want to use HTTP as my communications protocol? IE6 seemed to be able to, FF, Opera and Safari seems to be able to. For pete’s sake, you’re a web browser! What other bloody protocol do you normally use? If I were ever to type anything in the address bar, and I didn’t specify http://, ftp://, file:// etc., the chances are that, in actual fact, I really, actually, meant, http://, surely?

Tags: HTTP, IE7
Posted in Grinds My Gears | No Comments »

blog

When will M$ drop support for IE6?

2008.10.08

Whilst working with IE6 recently, ha, sorry I mean against IE6 – I found that a number of times I was asking (read: wishing) when support for this horrendous browser would be dropped. According to http://cmsreport.com/node/1812, support could be dropped when mainstream support for XP is dropped. Wouldn’t that be great? But hang on, isn’t everyone doing their best to avoid upgrading to Vista, hoping that M$ doesn’t drop support, or even stop allowing new PCs to be shipped with it until Windows 8? It seems that we have a bit of a conflict of interest here, meaning I don’t think there is a way of getting rid of IE6 whilst keeping XP – which is annoying, to say the least.

Tags: IE6, Internet Exploder 6, XP
Posted in Grinds My Gears | No Comments »

blog

If you’re going to get one thing for mountain biking…

2008.08.10

If you’re off mountain biking, thats proper trails riding I mean and not just a casual ride in the park, I’d recommend you buy some cycling gloves. Obviously a helmet as well, but to be honest that should be a given. Its like me suggesting you buy a bicycle to go mountain biking.

Anyway, gloves, yes. My hands feel like I’ve been rubbing them against a cheese grater all afternoon. I shall be buying some gloves before I go mountain biking again.

Tags: cycling gloves, mountain biking
Posted in Sports | No Comments »

« Older Entries


archives

  • July 2010
  • May 2010
  • February 2010
  • January 2010
  • December 2009
  • December 2008
  • October 2008
  • August 2008
  • May 2008

categories

  • Blog (1)
  • Grinds My Gears (5)
  • Hosting (2)
  • JavaScript (1)
  • PHP (1)
  • Sports (1)
  • SQL (1)

meta

  • Entries RSS Entries
  • Entries RSS Comments
  • powered by WordPress

footer menu

  • valid xhtml & css
  • accessibility information
  • © 2010 freestyle developments
  • design by element-media