Information Archives

Editing and customizing error messages in Wordpress: wp-db.php

Wordpress has a cool plugin system that allows for various template changes. Sometimes, though, some defaults are planted in the program that require hacking the code to remove. By creating your own 404.php template and storing in the template are you can have it match the design of the rest of your blog, but what […]

PHP Security Guide

The PHP Security Guide discusses and explains in depth PHP security issues, including many code examples:
If you do not design your application with security in mind, you are doomed to be constantly addressing new security vulnerabilities. Careful programming cannot make up for a poor design.
Even a little security philosophy in there. Definitely worth bookmarking.

Using floor and time to calculate number of days elapsed from UNIX timestamp

Finding out the number of days elapsed from a UNIX timestamp is actually pretty straightforward. If you only know two dates then first you’ll need to convert the date to a UNIX timestamps and then subtract the most recent timestamp from the older timestamp like this:

<?php
$old_timestamp = 1102971600;
$elapsed_seconds = time() - $old_timestamp;
print ‘Seconds elapsed since […]

How to use preg_replace to replace phrase between question marks

<?php
$string = “?This is a test that should be in single quotes quotes?”;
$text = preg_replace(”/(\?([^\?]+)\?)/”,”‘\\2′”,$string);
?>

regular expression produces:
This is a test that should be in single quotes’

How to make an anniversary counter announcement script using ordinal numbers

Today being it is our 16th wedding anniversary I decided it would be appropriate to build a small script to keep track and post a message automatically on our special day together. I wanted this program to remember what year of our anniversary it was without me having to remind it: a great use for […]

4 PHP debugging tips and tricks

So you are getting a weird parser error at a line of code that doesn’t have any errors? Here are some tips and tricks I’ve compiled over the 6+ years I’ve been doing PHP scripting for tracing various PHP errors in source code:
1. Start commenting out code near the parser error line number. Start by […]

Buying PHP shares in Yahoo Buzz Game

Yahoo in association with O’Reilly is running a free game called Yahoo Buzz Game where players are given $10,000 virtual dollars to buy into various technologies and news. Of course the first thing I bought into was PHP (shown above) but there are plenty of other markets (shown below):

The game is being powered by […]

How to PHP scripting course begins Friday 9/23/2005

For those who would like to learn how to write PHP code, starting next Friday at Webmaster Cookbook, our family friendly webmaster how-to site/blog, we’ll be going through a 32 week course on PHP programming. Details will be announced during the radio show and podcast next Friday September 23, 2005 at 3:30pm PST. For those […]

How to check the user’s browser type and platform

Sooner or later it might become necessary to write an application that tracks site visitor browser types. Here’s some code to use:

<?php
echo($_SERVER[‘HTTP_USER_AGENT’]);
?>

This will output something that looks like one of the following:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) 
Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC)
Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
Mozilla/5.0 (Windows; U; Windows NT 5.1; […]

How to find the location of php.ini on the server

Using the phpinfo() function you can easily find the location of the php.ini file on the server. Here’s the code to generate the phpinfo information pictured above:

<?php
phpinfo();
?>

Shown with the red arrows in the screenshot above:
#1 - this is the version of PHP
#2 - these are the configured library. For example ‘–with-mcrypt=/usr/lib’ means the mcrypt library […]