Counting to 1000 in PHP without loops or conditionals

Posted March 14th, 2011 in PHP by Andrew Curioso

Update: added a benchmark for performance comparison and updated the code to no longer rely on a fatal error to exit.

It started with one question:

Print numbers from 1 to 1000 without using any loop or conditional statements. Don’t just write the printf() or cout statement 1000 times.

How would you do that using C or C++?
Source: Stack Overflow

My favorite answer was an amazing example of obscure C. Using math to iterate between two function pointers (printf and exit). And while it brought back memories of my C days, I kind of left it at that.

Later in the day, one of my co-workers messaged me with his version of a 1-1000 iterator in PHP. So naturally, I had to write my own version.

Continue Reading »

Authentication vs. Authorization

Posted July 14th, 2010 in Security by Andrew Curioso

This seems like a no-brain-er but I have seen it more times than I can count and I have seen it happen to some very experienced developers. Put simply: authentication is not enough; you need to make sure that the authenticated user is actually authorized to perform an action. It is one thing to know who a user is and an entirely different — though equally important — thing to know what a user is allowed to do.

This article covers the concepts of authentication and authorization.

Continue Reading »