Posts Tagged ‘php’

Binary Code and Bitwise Operators (in PHP)

Sunday, April 6th, 2008

At it’s core, all of the information on your computer is made up of bits - or 0’s and 1’s. There’s quite a bit of interpretation that goes on between that basic binary code and the information as it is displayed on your screen.

However, you may find a time to work with data at the binary level in PHP (and many other programming languages). Here’s a quick guide to understanding binary numbers and the common operators for handling them.
(more…)

Moving Wordpress: Individual 301 Redirects with PHP

Sunday, March 23rd, 2008

I recently decided to move part of an old blog to an independent site.

In order to maintain the meager search engine and referral traffic that the old pages had, I planned on using 301 Redirects. I figured that I would re-create each of the old articles (~10 total articles) on the new site and set up an individual 301 Redirect to send users and search engine spiders to the new location.

The problem, however, was that the standard .htaccess rewrite that Wordpress uses was conflicting with the 301 Redirects. For some reason, they just weren’t working - so I turned to a PHP-based solution.
(more…)

Five Useful, Simple Wordpress Plugins

Thursday, March 20th, 2008

I’ve been playing around with developing Wordpress sites for a while now. I love how quick and easy it is to launch a site and update content.

One of the greatest features is the thousands of plug-ins available for Wordpress. You can find a plug-in for just about anything you want to do - or if you have some PHP know-how, you can develop your own.

Here are five basic Wordpress plug-ins that I’d recommend using for any project you start.
(more…)

How to Time Delay Posts in Wordpress

Saturday, March 8th, 2008

One reason I’ve heard people say that they prefer a full-blown CMS to Wordpress is that Wordpress doesn’t allow time delayed posting. I was about to figure out a way to mod Wordpress to make this possible - until I realized that there is some decent built-in functionality for time delaying.

You can easily delay the release of your posts into the main indexes (front page, archives, “Recent Posts” list, etc). With a little bit of code, you can also restrict people from viewing the page before its appointed “Published” date.
(more…)

How to Work With Directories in PHP

Thursday, March 6th, 2008

PHP offers a number of different functions to work with the local directory structure. There are at least three fairly simple ways to create and output a list of files in a directory.

Like the file functions, each method is slightly different. Knowing how each operates will help you choose which function to use when you want to work with directories in your PHP script.
(more…)

How to Enable Client-Side Caching of Resized Images

Saturday, March 1st, 2008

About a month ago, I wrote a tutorial on dynamically resizing images in PHP. Despite my best intentions, I never found the time to go back and rewrite the script to include server-side caching of the images created.

However, one reader asked if it was possible to enable a client-side cache of a dynamically resized image. It surely is, and it’s very simple.
(more…)

Combinations: General Function to Get All Possible Combinations

Thursday, February 28th, 2008

Previously, we looked at how to calculate a binomial coefficient (to find the total number of possible combinations) and an example of how to generate a list of combinations with hard-coded loops.

A function would be much more useful to us if it was flexible - if it could generate a list of combinations for any size set of numbers. We can’t do this with the hard coded loop solution, so we need to come up with a better method.
(more…)

How to Generate a List of Possible Combinations

Tuesday, February 26th, 2008

In statistics and probability, the combination is something special. There are tons of problems that revolve around how many combinations you can get choosing a certain number of random items from a set.

We’ve developed mathematical formulas to help us determine the number of possible combinations - and therefore the possibility of getting any single combination - but how can we generate a list of the actual combinations?
(more…)

How to Spoof a Form, or Why Your Form Isn’t Safe

Monday, February 25th, 2008

Forms can create all kinds of security holes in PHP applications. The biggest reason for this is that you can never be sure just what kind of input you’ll be getting.

There are some steps you can take later on to protect your applications from this unknown input. But first, let’s take a look at why you can never trust a user’s input and just how easy it is for someone to spoof a form.
(more…)

Getting Combinations: Calculating a Binomial Coefficient

Sunday, February 24th, 2008

I came across this problem on the DigitalPoint forums the other day. How can we write a script to calculate the total number of random combinations in a set (i.e. the binomial coefficient), and how can we generate a list of these combinations?

Today, we’ll tackle the first part. We’ll start with a quick primer on math - what is a binomial coefficient? Then, we’ll look into the most efficient way to calculate that and get the total number of possible combinations.
(more…)