jump to navigation

Installing PHP5 on IIS 6 with the GD Library July 31, 2008

Posted by admin in : Tips, PHP , add a comment

So after spending about three hours on my windows machine here at work trying to get PHP and GD to cooperate with IIS, I thought I would write about it to save everyone some headaches. Now, just as a preface, as much as I dislike windows, especially since thanks to darwinports or fink on my mac I am able to install everything I need with one command, I have to say that IIS really was not difficult at all to work with. Just make sure to adhere to the following steps and everything should work OK:

PHP setup

  1. Download the PHP 5 zip file from: http://www.php.net/downloads.php.

    Note: Make sure to download the zip package, and NOT the MSI Installer package.

  2. Extract the files from the zip package to the C:\PHP.
  3. Rename C:\PHP\php.ini-recommended to C:\PHP\php.ini
  4. Copy C:\PHP\php.ini to C:\WINDOWS\php.ini. If you wish, you can probably get away with creating an alias (symbolic link) in the C:\WINDOWS folder that points to the original php.ini file. It is important that there is a link or the actual file though, since this is where IIS will look for the configuration file.

Set up GD and other extensions

  1. Open up your php.ini file and search for the line: ;extension=php_gd2.dll and uncomment it by removing the semi-colon (’;'). Repeat this process for any other extension you wish to enable.
  2. Copy C:\PHP\php.ini to C:\WINDOWS\php.ini. If you wish, you can probably get away with creating an alias (symbolic link) in the C:\WINDOWS folder that points to the original php.ini file. It is important that there is a link or the actual file though, since this is where IIS will look for the configuration file.
  3. Finally, for each extension you enabled in the php.ini file, locate the corresponding dll file in C:\PHP\ext\ and copy it into the same directory as php.ini (C:\WINDOWS\).

Configure IIS

  1. Go to Start->All Programs->Administrative Tools->Internet Information Services and open up the ISS manager.
  2. Navigate through the folders to the Web Sites folder, expand it, and right click on Default Web Site and select ‘Properties’.
  3. Navigate to the Home Directory tab and select Configuration. Under ‘Cache ISAPI responses’ click ‘Add’ and input ‘.php’ (without the quotes) as the extension. For the executable, select C:\PHP\php5isapi.dll
  4. Recommended: Next, navigate to the Documents tab. Click add, and type in ‘index.php’ (again, without quotes). You can then move this up in the list to give it priority. This tells IIS that if it finds an index.php file in the directory, that is the default document that should be displayed.
  5. Close the properties window. Next, click on the Web Service Extensions folder. In the next pane, click Add New Extension. Type in extension name as php (without the leading ‘.’ !), and again for the Required Files browse for C:\PHP\php5isapi.dll. Check the box for Allowed, and click OK.
  6. Finally, as a last little tidbit of advice: Anytime you change the php.ini file, it is not necessary to restart IIS (one benefit it has over Apache). All you have to do is expand the Application Pools folder in the IIS Manager, right click on Default Application Pool, and click Recycle.

And that’s it, you are finished! To test out your installation, create a file called test.php and save it to your web directory, and place the following code in it:
< ?php phpinfo(); ?>

How to improve Site Load Times - Yet More Website Optimization Tips June 6, 2008

Posted by admin in : Uncategorized , add a comment

Reduce the Number of HTTP Requests

Abstract: Each object on a webpage, whether it is a script, image or stylesheet, requires a separate connection to be established from the client to the server. This accounts for the bulk of the time spent loading the page.

Recommendations:

• Compress/aggregate CSS files.
o Common tools like CSSTweak can help minimize CSS files.
• Compress/aggregate JS files.

Image Optimization

Abstract: There are a plethora of techniques to optimize images for delivery. Common techniques include sprite implementations, reductions in file size, etc.

Basic Image Optimization
Recommendations
• Reduce file size – most images, especially web banners, are needlessly large, and can be compressed using such tools as Adobe Photoshop.

CSS Sprites

Abstract: A CSS Sprite is an image file that contains multiple images within it, which can be displayed properly through the CSS background-position property. By grouping multiple images into one composite image, only one HTTP request needs to be sent, and only one file needs to be cached to display all of the requisite images. Both AOL.com and Yahoo.com have been using CSS Sprites to minimize overhead.

Recommendations:
• Create an evenly spaced composite image of all the images that need to be displayed. As the background image of a property, CSS can shift the X and Y coordinates of the displayed portion of the image to any of the contained images.
• Use CSS Sprites for icons and other similar image types.

Inline Image Optimization

Abstract: Inline images use the data URI scheme to directly embed images into web pages. This saves HTTP connections, and when combined with CSS Image Sprites can help speed up a website’s loading time. However, inline images are not cached, and in order to cache these images, they must be referenced in the CSS stylesheet as a background image.

Syntax: data:[][;base64],

Recommendations
• Use inline images in stylesheets as much as possible, to help reduce overhead on a page that has many HTTP requests.
• Inline images should preferably be used for only small images; otherwise it may make more sense to send a large image through an HTTP response.

Notes
• Currently, Internet Explorer versions 5-7 do not support the data URL scheme. To get around this, conditional comments can be used to load a separate IE stylesheet which references the images normally, while using the data URL scheme for other browsers.
• The base64 textual representation of an image will be slightly larger than the binary image.
• In addition to saving HTTP requests, data URL’s also save concurrent threads, which is usually set to a default of 2 simultaneous requests to the same hostname, by the browser.

JavaScript Optimization

Abstract: When the browser reaches a

MySQL LOAD DATA LOCAL INFILE returns Column count does not match value count at row 1 error April 29, 2008

Posted by admin in : Tips, PHP , add a comment

Finally back after a long time! Here is a quick tip to get everyone started, and I will put more up as soon as I get some free time.

Scenario: I have a comma-separated value list (*.csv) file that I would like to import into my database. However, I put in the code:

LOAD DATA LOCAL INFILE '/path/to/csv/file.csv'
INTO TABLE test_table
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'

and I get an error: Column count does not match value count at row 1.

Now, normally when I see this error I immediately think that I am trying to insert values into more columns than there actually are in the table. Once I verify that I am assigning one value per column, and that EVERY COLUMN gets a value, the next thing to check with an error like this is the primary key column. Usually this will be an auto_increment column, but it still needs a value when inserting into a row. If you are simply adding to the file, you can use ” or ‘\N’ as a value for this field - it will automatically assign itself the next proper number in the sequence.

Now, if you are in the situation I was in, this still didn’t help you. At this point, this is usually because Excel was used to generate the CSV file. If Excel sees a comma in a cell, and is told to save as a CSV, then Excel will take that cell and enclose it in quotations (”Cell, contents”). However, the SQL code is told to split into columns at EVERY COMMA. Therefore, it is trying to split at the comma, and add in more columns to the table to handle the leftover chunk of the cell, pushing every value over. Luckily, there is an easy fix for this. Simply use the code:

LOAD DATA LOCAL INFILE ...
...
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY “”"”


The OPTIONALLY ENCLOSED BY option will tell MySQL to split at a comma to determine fields, but to skip over anything in quotes, leaving it intact.

NOTE: The use of the keyword LOCAL in the SQL query is to allow the user to select the file from anywhere on the hard drive. Otherwise, the user will not have access rights for the file. For more information, check the MySQL manual.

Hidden Preferences Part 1: The Dock (25+ hidden preferences!) January 18, 2008

Posted by admin in : Tips , add a comment

As most people are probably aware of by now, Apple has included numerous hidden features in their applications. While many of these hints are already included at http://macosxhints.com/, I am trying to provide a fully comprehensive list here, along with some options with results that I have not yet been able to determine as well. So far I have cataloged over 25 hidden preferences.

1. mouse-over-hilte-stack -bool (YES | NO)
This code will make any item you hover over in the stacks highlighted. This is the same highlight that appears when using the arrows to navigate the files. This only works if the stack displays as a grid.

After activation of mouse-over-hilte-stack

3. min-effect (scale | suck | genie)
The hidden preference here is the ’suck’ option. This changes the minimize effect to a sucking motion.

2. Immutables. THe following immutable commands prevent modification of their respected immutable properties. If one of the immutable properties are set, the respected feature in the system preferences pane will also be greyed out.
contents-immutable -bool (YES | NO)
“Locks” the Dock and prevents user from adding new applications to it.
size-immutable -bool (YES | NO)
Prevents resizing the Dock.
magnify-immutable -bool (YES | NO)
Prevents toggling the magnification setting.
autohide-immutable -bool (YES | NO)
Prevents changing the authohide setting.
position-immutable -bool (YES | NO)
Prevents moving the Dock to a new position.
min-effect-immutable -bool (YES | NO)
Prevents toggling the minimize effect.
min-in-place-immutable -bool (YES | NO)
Not a clue what this does.

3. no-bouncing -bool (YES | NO)
Prevents that annoying icon bounce if an application is trying to tell you something. I found this especially useful when dealing with Microsoft Office, since every time I launch one of their applications and go to another application instead of waiting for Word or Excel to load, the icon bounces to get my attention, which I find extremely irritating.


(more…)

Apple Leopard 10.5.1 Applications crash when printing November 27, 2007

Posted by admin in : Tips , add a comment

After upgrading from 10.5 to the 10.5.1 update via the Software Update preference pane, I found that when I attempted to print, from any program, the program would hang and then crash. Additionally, attempting to go into System Preferences and attempt to load the Print & Fax preference pane, System Preferences would also hang and crash.

After two days of frustration, I figured out the simplest, most obvious way to fix this problem. I simply downloaded the standalone 10.5.1 update package from Apple at http://wsidecar.apple.com/cgi-bin/nph-reg3rdpty2.pl/product=16133&cat=60&platform=osx&method=sa/MacOSXUpd10.5.1.dmg, and this solved my problem.

If, however, this does not work, another method if you are able to get into the Print Preferences is to remove the printer, reinstall the printer drivers from the Leopard CD, and then add the printer again.

Useful Leopard tips, tricks, hacks and more! November 15, 2007

Posted by admin in : Tips , add a comment


Just bought Leopard, and already want to make some changes? Check out some of these hints and see if they help! (For more general tips, check out my other Mac Tips post here)

  1. The Dock - I personally enjoy the Dock. It looks great, its classy and showy, and thats what I love. However, for those who prefer a minimalist approach, or just don’t like all the glitz, there IS a way to get rid of the annoying glass background. You can change your Dock from glass to translucent smoke if you want. One advantage to this, as I have to admit, is that it makes it much easier to see the indicator lights for open applications.

    Glass Dock

    Smoke Dock

    To accomplish this change, simply open up Terminal.app and type:
    defaults write com.apple.dock no-glass -boolean YES
    KillAll Dock

    To reverse the effect, retype the same commands, but instead of YES type in NO.

  2. If you want to get back those old Tiger black indicator arrows, then Silver Mac has just the solution, so be sure to check it out!
  3. I mentioned this in my earlier post, but I am going to mention it again here - Safari 3 for Leopard has an amazing new feature called Web Inspector. This allows you to essentially view the source of a dynamic page. If the content of a page changes due to javascript or AJAX, chances are if you view the source you will not see that code, but the Web Inspector lets you inspect the dynamic source. It is extremely easy to use, found in the context menu after you enable it. You can navigate the DOM structure, look at all dependant files, scripts, styles and images, as well as any errors.
    To enable the inspector, type in:
    defaults write com.apple.Safari WebKitDeveloperExtras -bool true
    Again, to undo this simply retype the command and type in “false” instead of “true”.
  4. While on the subject of Safari, another nifty feature is the ability to change the progress display. Normally, to indicate progress the address bar will fill up with a blue progress bar. This can be replaced by having the favicon (the little icon next to the URL) change into a pie graph to indicate loading progress.
    To enable this feature, type:
    defaults write com.apple.Safari DebugUsePieProgressIndicator -bool false
    Safari with Pie chart loader
  5. While not really Leopard related, I came across a great site that lists a bunch of startup options for booting your mac. The site is: http://www.jacsoft.co.nz/Tech_Notes/Mac_Keys.htm#Command-Shift-Option-Delete
    Here are a few useful ones to know.

    Zap PRAM CMD+OPT+P+R
    Close Finder Windows OPT (Hold before Finder launches)
    Boot with Virtual Memory Off CMD (Only lasts until the computer is restarted
    Select Volume to Start From OPT
    Safe mode SHIFT



Leopard Installation Tips and Help November 2, 2007

Posted by admin in : Uncategorized , add a comment

Leopard is out! This article is meant to help you install Leopard with the minimum amount of hassle.

First, even though it seems obvious, prior to installing Leopard make sure to backup you data! I cannot stress this strongly enough. If, for some reason, something happened during installation which forced you to wipe your hard drive, you will have lost all of your information. For backups, you can either just drag folders to your external hard drive, or make a full, bootable backup using a third party application, so you are able to have a bootable volume in the event of the unforeseen. A good program that I highly recommend is RSyncX.

Next, if you are performing an upgrade and not making a clean install or an Archive Install, then search your computer for any instance of Application Enhancer. If you find any trace of Unsanity’s Application Enhancer bundle, and you wish to keep it, go to their website and download their update. Otherwise, delete ALL traces of this bundle. If you keep any part of this bundle on your computer, and it is not the newly released update, you WILL face the equivalent of a BLUE SCREEN OF DEATH!

Now you are ready to install Leopard. Make sure to unplug ALL USB devices from your computer before beginning installation. I had my computer hang on me for ages before I realised that is why installation did not begin.

After clicking on Restart in the Installer, you will be able to select your installation type. On the next screen, click customize. You will see different options for add-ons. Unlike Tiger, Leopard assumes that you want ALL fonts installed, which takes up space. Make sure you check only what you need, and then continue your installation. After about 30 minutes, enjoy Mac OS X 10.5!

Leave any tips for Leopard in the comments, I would love to hear them!

Handy Javascript Tips and Tricks October 3, 2007

Posted by admin in : Tips, Javascript , add a comment

Repeating code is unfortunately one of those annoyances of programming. That is why I have fallen in love with the with statement in Javascript. If you have a long object that you will use a few times, such as the object: document.getElementById(’id’).style.color and document.getElementById(’id’).style.width, then you may want to consider using the with statement:


function changeStyle() {
with(document.getElementById('id').style) {
color = 'blue';
width = '100px';
}
}

As you can see, this can be a huge timesaver, whether you are working with getting select input values, multi-dimensional arrays, and more.

Freeing up space on the Mac August 11, 2007

Posted by admin in : Tips , add a comment

There have been many excellent articles on this topic, but here is just a brief overview if you need to find spare space on your computer:

  1. iDVD takes up a loooot of space - about 1.7GB!!! If you are looking for a free, reliable and above all SMALL application, use ffmpeg. ffmpeg can be used either from Terminal (my personal preference, a good tutorial can be found here) or with a GUI frontend, ffmpegX. Don’t worry about deleting iDVD - if you really want it back, you can use your mac install disk to get it back without a problem, or simply burn it onto a blank DVD.
  2. Garageband is another program that is debatably useful, if not for the enormity of space it takes up. I play guitar and a couple of little dittys on the piano, and do use Garageband, but as I finally got an external hard drive, that is where Garageband and all the Apple Loops are located. As Garageband takes up over 2GB with all of its supporting files, unless you use it, you are better of deleting it and the Apple Loops folder completely, as it is not necessary for your computer and frees up a lot of space. The application can be reinstalled just like iDVD - from the install disk. If you wish to use Garageband, but on an external drive, then the great Garageband Anywhere program is for you! You can install the Garageband app from your install disk on your external drive with this program, or even move your existing application and support files to an external drive, with just a click of the button!
  3. World Book 2005. Why?! I personally have not found one use for this application that Google could not solve. It takes up over 2GB of space, and it was definitely a happy moment in my life when I pushed that Cmd-Delete button combination on it! Just get rid of the little sucker, or back it up on a blank DVD if you really want it.
  4. Languages. Most people only need their computer to operate in one language, and usually not more than three, if that. That is why I reccommend you use the Monolingual program to get rid of unneeded languages on your computer.

Safe Form Submissions July 30, 2007

Posted by admin in : Uncategorized , 2 comments

Just a quick post, until I get some more time to write.

Most forms out on the web today are insecure. It is possible to place SQL database commands into the submission area, and get access to the websites database file. This type of attack is called SQL Injection. Other forms can be modified externally by a hacker to submit any information they want, and to possibly obtain private information from your website.

I enjoy using custom functions for these purposes, as they allow simple adjustment options to your validation functions if needed. So lets say we have a function Validate_Field($input), which is used to validate the text entered in a field. In order to strip out any possible MYSQL characters or commands, we will use the mysql_real_escape_string($input) function. Then, if we also want to strip out any html, we can use PHPs htmlspecialchars($input) function.

These functions are just a start, but it will help you on your way to building more secure, reliable forms.