PHP Magazine December Issue
02 Dec 2005PHP Magazine just published their December issue. The cover article is an introduction to design patterns by Robert Peake. My column, Guru Speak, discusses the interesting things you can do with output buffering.
My favorite output buffering trick isn't really a trick at all - it's a relatively new (PHP 4.3+) function called output_add_rewrite_var(). This function makes the otherwise tedious chore of rewriting URLs very easy. For example, if you decide you want to propagate an auth token to strengthen your session mechanism, it's very easy:
output_add_rewrite_var('auth', '412e11');
Here's a larger example that demonstrates what this does:
output_add_rewrite_var('auth', '412e11');
?>
<a href="link.php">Click Here</a>
<form action="form.php" method="POST">
<input type="submit" />
PHP propagates the auth token in both the link and the form:
<form action="form.php" method="POST">
<input type="hidden" name="auth" value="412e11" />
<input type="submit" />