PJ Hile

Don’t worry, I’m from the Internet.

PJ Hile header image 1

PHP Authorize.net CIM API Class

June 24th, 2009 · No Comments

The Authorize.net CIM PHP Class allows you to interact with the Authorize.Net Customer Information Manager (CIM), which can be used to store your customers’ sensitive payment information on secure servers, simplifying payments for returning customers and recurring transactions. It can also help you to comply with the Payment Card Industry (PCI) Data Security Standard, since customer data is no longer stored locally. It is an ideal tool for businesses that need to securely save customer data and provide convenience for their customers.

This is a derivative work of the class created by Ray Solomon/Josh (Version 1.3).  I needed the extraOptions functionality for Authorize.net’s FDS (Fraud Detection Suite), but was unable to get in contact with either authors to see if any updates were coming down the pipe.

Download Version 1.3.1
Updated: June 24, 2009

Files included:

  • authorizenet.cim.class.php
  • examples.php
  • LICENSE.txt

→ No CommentsTags: PHP · PHP Authorize.net CIM API Class

CakePHP save/saveAll methods not displaying validation errors

February 3rd, 2009 · 2 Comments

Just thought I’d leave a quick note to myself about validation errors not showing up when I use read() after a save() or saveAll(). The key is to use a conditional for the read() or I believe using find() work as well.

Won’t show validation errors:

if (!empty($this->data)) {
  if ($this->User->saveAll($this->data, array('validate'=>'first'))) {
    $this->Session->setFlash('User saved');
  } else {
    $this->Session->setFlash('User not saved.');
  }
}
$this->data = $this->User->read(null, $id);


Will show validation errors:

if (!empty($this->data)) {
  if ($this->User->saveAll($this->data, array('validate'=>'first'))) {
    $this->Session->setFlash('User saved');
  } else {
    $this->Session->setFlash('User not saved.');
  }
} else {
    $this->data = $this->User->read(null, $id);
}

→ 2 CommentsTags: CakePHP · PHP

Ignoring CakePHP’s tmp/ directory with Subversion

July 30th, 2008 · 6 Comments

I’ve noticed on many occasions that I’ll start a project with a Subversion repo and immediately add/commit all the files included with Cake’s nightly build including the tmp/ directory.  If you’ve ever done this, you’ll know it’s kind of a pain always having those cache/log files showing up when you commit.  So, for my benefit, I’m posting these few lines of code in order for me to refer to later.

From the app/ directory:

svn export tmp tmpBAK
svn rm --force tmp
svn ci -m 'Removing directory "tmp".'
mv tmpBAK tmp
svn propset svn:ignore 'tmp' .
svn ci -m 'Ignoring "tmp" directory.'

→ 6 CommentsTags: CakePHP · PHP · Subversion

Changing the CakePHP Auth component password hash

May 29th, 2008 · 7 Comments

In moving some legecy sites over to CakePHP, I’ve come across some situations where I need to the Auth component to ‘hash’ the password differently. For example, just a straight md5() of the password.

To accomplish this, you need to empty your Security.salt variable in /app/config/core.php (Not positive what all this will affect):

Configure::write('Security.salt', '');

and change the hash method of the Security class (I did this in app_controller.php):

function beforeFilter(){
   Security::setHash('md5');
}

→ 7 CommentsTags: CakePHP

Twitter client for Ubuntu

May 22nd, 2008 · 4 Comments

TwhirlTwhirl is an Adobe Air based Twitter client, and one of my favorites for use on my Dell Latitude D630 running Ubuntu Hardy Heron.  For instructions on how to install Air, click here. Then, download/install Twhirl from here.  Total install time is 5-10 minutes.

→ 4 CommentsTags: Twitter · Ubuntu

Bluetooth on Dell D630 – Ubuntu 8.04 Hardy Heron

May 6th, 2008 · 2 Comments

Dell UbuntuIt took a little bit of work for me to get my Dell bluetooth mouse and keyboard working with my new work laptop (Dell D630), but in the end it was pretty easy.

First, make sure gnome-bluetooth and bluez-gnome are installed in Synaptic.  Then, in a terminal type “sudo hidd –search” and click the little bluetooth button on the underside of the mouse/keyboard.

→ 2 CommentsTags: Dell · Ubuntu

Putting a Google Map on your site with PHP: Part 1

March 24th, 2008 · 1 Comment

Google MapThe first step in getting a Google map on your site is to get the latitude and longitude coordinates of all the points you want to show. I get my coordinates using geocoding in the Google Maps API. In order to use the Google Maps API, you must sign up for a free key here.

Once you have your key, it’s as simple as:

// Desired address
$address = "http://maps.google.com/maps/geo?q="
.urlencode($data['address'])
.",+".urlencode($data['city'])
.",+".urlencode($data['state'])
.",+".urlencode($data['zip'])
."&output=xml&key=".$_SESSION['GOOGLE_KEY'];


// Retrieve the URL contents
$page = file_get_contents($address);


// Parse the returned XML file
$xml = new SimpleXMLElement($page);


// Parse the coordinate string
list($longitude, $latitude, $altitude) = explode(",", $xml->Response->Placemark->Point->coordinates);

We now have $longitude/$latitude, which we will need for rendering our map.

Notes:

  • I used to get the coordinates inside of my map generation, but sometimes the map would finish rendering before all the coordinates had been downloaded, so I suggest you get all your coordinates before you render your map.
  • My example makes use of SimpleXMLElement() which I believe is a PHP5 and above only function. If you use PHP4 or below, you will have to parse the xml some other way.
  • You don’t need the altitude for map generation, but they give it to us anyway.

→ 1 CommentTags: Google · PHP

Javascript strings over multiple lines from PHP

March 13th, 2008 · No Comments

I had a problem where I was defining javascript variables from php variables, and the php variables had multiple lines.

So, a function like this:
function SomeFunction() {
var variable = "<?php echo $variable; ?>";
}

was creating this:
function SomeFunction() {
var variable = "The first row.
The second row.
The third row
";
}

The fix was to replace all the ‘\n’ with ‘\\n’, so the literal string ‘\n’ is output instead of an actual line break.

Like so:
var variable = "<?php echo str_replace('\n', '\\n', $variable); ?>

→ No CommentsTags: Javascript · PHP

Send more data with CakePHP’s observeField()

March 10th, 2008 · 6 Comments

CakePHPI just ran into a situation today that required me to have access to more than one form field when doing an ajax request within my CakePHP application. Basically, when someone is typing an address, I want to check Google’s Geocode API for a latitude and longitude coordinate.

The important part is the ‘with’ option:
'with'=>'Form.serializeElements($("CommunityForm").getElements())'

My example:
echo $ajax->observeField('CommunityAddress', array('with'=>'Form.serializeElements( $("CommunityForm").getElements() )','url'=>'geocode','update'=>'geocode'"));

  • The data being passed can be accessed in $this->params
  • This solution requires the Prototype javascript library.

→ 6 CommentsTags: CakePHP

Command line script to recursively delete .svn folders from a directory

January 17th, 2008 · 3 Comments

find ./ -name ".svn" | xargs rm -Rf

source: http://www.rickhurst.co.uk/category/linux/

→ 3 CommentsTags: Uncategorized