SiteCrafting Blah Blah Blog

Jan. 9, 2008 at 3:51pm

PHP Passes Homeland Security Test

Use open-source with more confidence

When meeting with prospective new clients, we tell them that SiteCrafting uses PHP and MySQL as the development platform. Invariably this leads some of them to ask us what PHP and MySQL are and if they are safe and fast. Sometimes, this can lead to interesting conversations, where we explain to them why we think PHP and MySQL are safe and fast.

Occasionally, there's a client who remembers reading an article 4 or 5 years ago about PHP 3 having some security issues. We refer them to current articles on PHP and mention our own experiences, but the latter argument can come across as "Because we say so," which isn't a good way to get the point across.
Read more

Comments (0) | Posted in Odds 'n Ends, PHP, Security by Ken Foubert


Nov. 30, 2007 at 1:05pm

Why is AOL denying email?

Try adding a parameter to the mail() function

Email debugging is often frustrating and time consuming. There could be numerous reasons why the email you attempted to send out through your code fails: routing issues, firewalls, company servers blacklisting or blocking incoming emails, spam filters, bad DNS records, and email header requirements. The last one can definetely lead to infinite frustration, as I have experienced in the past, and was recently the cause of why AOL was denying emails generated by the php mail() function.

Read more

Comments (1) | Posted in From the Workbench, PHP by Ken Foubert


Nov. 28, 2007 at 4:16pm

Star Wars IV Animated ASCII Art

A blast from the past

In a recent The Code Project Insider email newsletter, there was a link to an animated ASCII art for Star Wars IV, A New Hope. This brought back fond memories of a bygone era, where I cruised the ASCII based bulletin boards on my trusty Color Computer, the CoCo, and played ASCII art games, such as Voyage of the Valkyries (a game written by my Keithley Jr HS teacher Mr. Leo Christopherson*) and Star Trek, on my school's TRS-80 Model 4, trash 80. I also had the experience of entering the code for several ASCII art games from a book, where I learned that the GOTO statement is very dangerous, especially if you put in the wrong line number.

Read more

Comments (1) | Posted in Odds 'n Ends by Ken Foubert


Sep. 12, 2007 at 4:52pm

AJAX & IE Caching Issues

I've been working on a project that involves using the jQuery javascript library and the Ajax methods. I've been happily using the Ajax jQuery.get() method to handle simple calls, such as a link that allows a user to view a list of words based on their selection, getting the contents of a tab when the user selects a tab, and finally getting the current weather after the person enters a new zip code, which is then saved to the database.

For the last operation, I got the JavaScript working great on Firefox and I thought it was working in Internet Explorer. However, after some testing, I noticed that the same weather data was being returned, even after a new zip code on the opposite coast was selected. Mmmm, I was rather baffled, especially since I've been using this jQuery.get() on the other functions, and encountered no problems like this.

Read more

Comments (0) | Posted in From the Workbench, Javascript by Ken Foubert


Aug. 9, 2007 at 4:14pm

Getting the Client’s IP Address

There are a number of reasons why you may want to capture a web user's IP address. You may want to only allow certain IP addresses to view your website, to allow only one vote per IP address, track unique clicks on links and buttons, a location of web users on Google Maps using MASHUP, and whatever else you can think of.

Below are a couple of examples to get the client's IP address in PHP and ASP.net, along with a couple of things to watch for.

Read more

Comments (0) | Posted in ASP.NET 2.0, Coding Techniques, From the Workbench, PHP by Ken Foubert


Jul. 27, 2007 at 2:56pm

PHP Code in The Background Part 2

Passing Arguments To Command Line

The blog entry How To Run PHP Code In The Background discussed how to run a php file through the command line using php's exec() command.  Recently, I needed to pass a querystring to the php file, but this is not possible through the command line. If you try to pass a querystring, the exec() command will fail.

Fortunately, after some googling, I came across a forum post that mentioned how the global array $_SERVER["argv"] can be used to get arguments being passed through php. I then followed the link on that page to Chapter 43. Using PHP from the command line on  the php.net website. Under the user contributed notes, I found a nice little function for getting the arguments and placing them into an array, similar to $_GET, $_POST, and $_REQUEST.

Read more

Comments (0) | Posted in From the Workbench, PHP by Ken Foubert


Jul. 23, 2007 at 5:29pm

ASP.net 2.0 Gridview vs. Custom Coding

A balance of needs and time

I recently decided to try the Gridview control in asp.net 2.0. I read some documentation and decided that it would be very easy to implement. I started by following a step-by-step tutorial on creating a table using the Gridview control, which uses the SqlDataSource control. This step-by-step tutorial included details on how to add paging, column sorting, updating a record, and deleting a record. The tutorial can be found here.

I was actually excited when I got this to work and how easy it was to do. It would only take a few minutes to create a simple, paged, sortable table where a user can delete and update records right on the page. Please note that simple is the operative word here.
Read more

Comments (2) | Posted in ASP.NET 2.0, Coding Techniques, From the Workbench by Ken Foubert


Jun. 4, 2007 at 11:31am

ASP.NET 2.0 Tips - Shared Functions

Visual Basic for ASP.NET 2.0

When developing a recent project for ASP.NET, there was a need to migrate a large number of generic functions that were created in PHP into the .net web project. For .net 1.0, you were able to add a code page that could be used for creating a bunch of functions. However, in .net 2.0, you still had the ability to add a code page, but it had to be a class. This meant placing all of our migrated functions as methods inside a class. To use a generic function, such as generateNewPassword(), you would have to first create a new object for the class and then call the method. Read more

Comments (0) | Posted in ASP.NET 2.0, Coding Techniques, From the Workbench by Ken Foubert


Apr. 18, 2007 at 1:08pm

PHP PEAR and include_path

When attempting to use the SMTP library from PEAR for a project, I was having problems with including the file. I kept getting a file stream error for this code:

require 'Net/SMTP.php';

I figured the problem had to be related to the include_path setting in the configuration file.

Read more

Comments (0) | Posted in Coding Techniques, From the Workbench, PHP by Ken Foubert


Apr. 13, 2007 at 2:19pm

How To Run PHP Code In The Background

PHP Asynchronous Programming

If you have php code that would take longer than 5 minutes to run, what would you do?

You could update the configuration file for apache, or whatever web server you're running, to increase the amount of time a script page is allowed to run  and then use php's ini_set("max_execution_time", seconds) to increase the amount of time php will allow a script to run.

Or you could use a session variable to mark the last position of the script and then use meta-refresh to start the script at the last position.

Or you could try an asynchronous call by using php's exec command.
Read more

Comments (9) | Posted in From the Workbench, Odds 'n Ends, PHP by Ken Foubert


Apr. 2, 2007 at 2:36pm

PHP cURL and SSL Connection Timeout

I've been working on a web site that uses cURL for request/response transactions and I was encountering a number of problems with empty responses from the server. This caused some frustrations, since these empty responses caused entire sections of a web page to be empty, especially on searches. Well, I couldn't have that, since people using the website would be confused on why a search for an item only worked occasionally. Trust in the web application would drop dramatically. Read more

Comments (2) | Posted in From the Workbench, PHP by Ken Foubert


Feb. 20, 2007 at 2:53pm

Optimizing GROUP BY with Multiple LEFT JOINS

Creative use of temporary tables

At SiteCrafting, I enjoy working with a large number of different projects, each with their own requirements, technology, and problems to be solved, unfortunately, I sometimes forget about past solutions, until after I have finished writing a piece of code. Such is the case with a query that was eating up some serious processing time.

The problem was with a GROUP BY query with LEFT JOINs to several other tables and summing up totals from those joined tables. This query was taking about 4 minutes 45 seconds to run, and worse yet, it was affecting searches which had nothing to do with that query, and probably also eating up precious memory and cpu resources.

Read more

Comments (0) | Posted in From the Workbench, MySQL, PHP by Ken Foubert


Jan. 19, 2007 at 4:52pm

Emulating Form POST in PHP

There's small choice in rotten apples.

Recently, I had a need to POST a form, using PHP script, to a remote url.  As I started to research a solution, I soon realized there were very few limited options.

Read more

Comments (4) | Posted in Coding Techniques, From the Workbench, PHP by Ken Foubert


Nov. 3, 2006 at 10:51am

How To Full-Text Search

Inspired by Joe's MySQL Cross Table Content Search


Here's a quick how-to on implementing Full-Text Searching using Microsoft SQL Server 2005. Originally, I planned on just using LIKE statements in the WHERE clause of an sql query, however, this would not be possible since, as I posted earlier in MS SQL Server 2005 text and ntext, that string functions do not work on text and ntext data types.

That's when I remembered Joe's blog entry about Cross Table Content Search, which he also mentioned in the office a couple of times before his entry. After that, I've been wanting to implement the Cross Table Content Search, and did not get the opportunity until developing the search page for the Pierce County Library.
Read more

Comments (0) | Posted in ASP.NET 2.0, From the Workbench, MS SQL Server by Ken Foubert


Oct. 27, 2006 at 11:25am

MS SQL Server 2005 text and ntext

text, ntext, and image data types have been deprecated

How I discovered that text, ntext, and image data types have been deprecated and replaced by varchar(max), ntext(max), and varbinary(max).

Recently, I needed to perform a query to update a number of links for the Pierce Count Library website. I thought I could use a simple REPLACE() string function, unfortunately, this turned out not to be the case. In order to update text and ntext datatypes using a query you're limited to a few functions, in my case I would be forced to use SUBSTRING() or UPDATETEXT().

Read more

Comments (1) | Posted in ASP.NET 2.0, Coding Techniques, From the Workbench, MS SQL Server by Ken Foubert


Oct. 24, 2006 at 9:41am

Group By Queries for MS SQL Server

Applying MySQL Wizardry to MS SQL Server

Back in the day, we worked on developing a specialty application that was basically a lead generation system with a database that stored over 200,000 records, with a potential for a lot more. The web application displayed numerous reports that calculated totals from disparate sources. We discovered that once our client began adding all their data that those reports were running slower and slower and slower.

The problem was that we had one primary query to pull the records out, then, as the code looped through each record, several other queries were needed to calculate the disparate totals. That resulted in numerous database calls that slowed the entire web application. That's when Mike discovered MySQL Wizardry, that used the SUM(IF()) and the GROUP BY clause, problem solved.
Read more

Comments (4) | Posted in Coding Techniques, MS SQL Server, MySQL by Ken Foubert