A blend of programming and seo

Connecting to authorize.net with php

What is authorize.net?

The Authorize.Net Payment Gateway is a secure Internet bridge between merchant businesses and the credit card and electronic check payment processing networks. We provide merchants with fast, reliable and secure passage for transaction data via a 128-bit Secure Sockets Layer (SSL) Internet Protocol (IP) connection, and manage the complex routing of payment information to the appropriate credit card processors. See a diagram that illustrates a typical Authorize.Net credit card transaction.

The Authorize.Net Payment Gateway is available to merchants seven days a week, 24 hours a day. The payment gateway offers many features and options that can be tailored to specific merchant business models.

Where do I start?

The first thing that you need to do, is signup with a test account. This will allow you to test out transactions to make sure your scripts are interfacing properly with their API. Here is the URL for getting your account:

http://developer.authorize.net/testaccount

API documentation can also be found here:

http://www.authorize.net/support/AIM_guide.pdf

after signing up, you should receive your new account info within 48 hours.

The Code

I have a library available here. It is originally written by Micah Carrick and is under the GPL/GNU public license. I have made some important additions to the main library, which are needed for it to function properly.

Requirements: PHP version 4 and above with the CURL extensions enabled

The following 3 files are contained in the above .zip download:

authorizenet.class.php – main class library for connecting to the authorize.net gateway
demo.php – an example driver file that shows how to use the library file. A test transaction is made to the main gateway.
ca-bundle.crt – main certificate file required by CURL for SSL transactions (windows users can place this in c:\windows\system32)

Important Variables that you need to change

Location: authorizenet.class.php

curl_setopt ($ch, CURLOPT_CAINFO,"c:\\windows\\system32\\ca-bundle.crt");
curl_setopt ($ch,CURLOPT_CAPATH,"c:\\windows\\system32\\ca-bundle.crt");

change the 3rd parameter “c:\\windows\\system32\\ca-bundle.crt” to the location of your CRT file.

Location: authorizenet.class.php

var $gateway_url = "https://test.authorize.net/gateway/transact.dll";

it currently points to the authorize.net gateway for test accounts. If you have an account that is performing real transactions, change this variable to the following value: “”https://secure.authorize.net/gateway/transact.dll”

Location: demo.php

$a->add_field('x_login', 'YOUR_USERID');
$a->add_field('x_password', 'YOUR_PASSWORD');

change x_login to your Login ID (not partner ID)
and x_password to your password

You should have received both of these in an email from authorize.net

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

June 23, 2009   No Comments

How to create a zip archive using PHP

The following is a library that allows you to generate zip file archives using php.


<?php
include('ziplib.php');

$zipfile = new Ziplib;
$zipfile->zl_add_file('This is a test file','path/to/file','g9');
//You can stream the ZIP file or write it in a file on your server
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename=\'testfile.zip\'');
echo $zipfile->zl_pack('zip file comments');
?>

This script will dynamically create a zip archive using the files specified with zl_add_file and output it to the browser (the final zip file will be named: testfile.zip).

Options

zl_add_file allows you to specify the compression level of the file file that will be added to the archive.

  • n (none)
  • b (bzip)
  • g (gzip)

Download

The php zip library can be downloaded Here

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

June 17, 2009   9 Comments

Free msdn subscriptions for startups

Microsoft recently announced a new program (called BizSpark) for startups that allows them to get a MSDN for free. This is a great deal, because msdn subscriptions normally cost over $1000/year (depending on the type plan that you buy). You can also renew for up to 3 years (unless your comapny goes public or is acquired by a company that does not itself qualify for BizSpark).


How do you qualify?

Your statup is:

  • Developing Software
  • Privately held
  • Less than three years old
  • Making less than US $1M annually

What kind of free software do you get?

Visual Studio Team System 2008:
- Visual Studio Team System 2008: Team Suite
- Visual Studio Team System 2008: Development Edition
- Visual Studio Team System 2008: Architecture Edition
- Visual Studio Team System 2008: Test Edition
- Visual Studio Team System 2008: Database Edition
- Visual Studio Team System 2008: Team Foundation Server Standard Edition
- Visual Studio 2008 Professional
- Visual Studio Team System 2005:
- Visual Studio 2005 Team Suite
- Visual Studio 2005 Team Edition for Software Developers
- Visual Studio 2005 Team Edition for Software Architects
- Visual Studio 2005 Team Edition for Software Testers
- Visual Studio 2005 Team Edition for Database Professionals
- Visual Studio 2005 Professional
- Visual Studio 2005 Tools for Microsoft Office System
- Visual SourceSafe 2005
- Previous versions of Visual Studio

SQL server – all versions

Windows Vista
- Ultimate/Enterprise/Business/Home Premium/Home Basic
Windows XP
- Professional/Home/Media Center Edition/Tablet PC Edition
Windows Server 2008 (all versions)
Windows Server 2003 R2
Windows Compute Cluster
Windows SharePoint Service

Office Ultimate/Enterprise/Professional Plus/Professional 2007
- Office Word, Office Excel, Office PowerPoint, Office Outlook & Business Contact
Manager, Office Access
- Office Publisher, Office InfoPath, Office OneNote, Office Communicator, Office
Groove, Office SharePoint Designer, Office Visio Professional, Office Project
Standard
- Office Accounting, Office Business Scorecard Manager, MapPoint, Office
FrontPage
- Office Project Professional
- Office Project Server, Office Project Portfolio Server

If your startup qualifies, you can signup here

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

June 16, 2009   No Comments

How to create Microsoft Office Documents with PHP

There are two main ways to build Excel, Word, and PowerPoint documents using PHP. The first is by using the COM library (only if you are using a Windows server) and the other is by using a more standardized approach such as HTML or CSV.


Dynamically creating a word document:


<?php
$word = new COM('word.application');

$word->Visible = 0;
$word->Documents->Add();
$word->Selection->PageSetup->LeftMargin = '2';
$word->Selection->PageSetup->RightMargin = '2';

//Setup the font
$word->Selection->Font->Name = 'Verdana';
$word->Selection->Font->Size = 8;

//Write some text
$word->Selection->TypeText('This is a test document');
//Save the document as DOC file
$word->Documents[1]->SaveAs('c:\\docs\\test1.doc');

//quit and release COM resources
$word->quit();
$word->Release();
$word = null;

?>

Dynamically creating an excel document

<?php
$excel = new COM('excel.application');
$excel->Visible = 0;

//Create a new workbook
$wkb = $excel->Workbooks->Add();
$sheet = $wkb->Worksheets(1);

//This code adds the text 'myvalue' on row 2, column 4
$sheet->activate;
$cell = $sheet->Cells(2,4);
$cell->Activate;
$cell->value = 'myvalue';

$wkb->SaveAs('C:\docs\test.xls');

//close and free resources
$wkb->Close(false);
$excel->Workbooks->Close();
$excel->Quit();
?>

Dynamically creating a powerpoint presentation

<?php
$powerpnt = new COM('powerpoint.application');
//Creating a new presentation
$pres=$powerpnt->Presentations->Add();
//Adds the first slide. '12' means blank slide
$pres->Slides->Add(1,12);
//Adds another slide. '10' means a slide with a clipart and text
$pres->Slides->Add(2,10);
//Adds a textbox
$pres->Slides[1]->Shapes->AddTextbox(1,20,50,300,40);
//Save the document as PPT file
$powerpnt->Presentations[1]->SaveAs('C:\Docs\test1.ppt');

//free resources and quit powerpoint
$powerpnt->quit();
?>

How to find Word, Excel, and Powerpoint functions

The following will show you all of the functions that are possible when accessing Microsoft Office components through php:

officephp How to create Microsoft Office Documents with PHP

  1. Open Microsoft Word, Excel, or Powerpoint
  2. Press Alt+F11 to start the Visual Basic Editor
  3. Press F2
  4. Find “ThisDocument” on the left. In the right frame you’ll see the available variables and functions that can be used with the COM object.
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

June 11, 2009   5 Comments

How to install Alternative PHP Cache

What is APC cache?

The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. It was conceived of to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.

Installing

APC Cache is not included with the latest release of php (although it is planned on being included with version 6). It says on the main PHP website that the .dlls can be downloaded from the pecl extensions package, but after downloading and extracting it, I realized that it is not there. I have found the correct .dlls and other files that are needed and they can be download from my server here.

After downloading and extracting the above zip file, complete the following steps:

1) copy the proper php_apc.dll (depending on your version) into your php extensions directory

2) add the following to your php.ini: extension=php_apc.dll (this should be placed under the other extension lines)

3) add the following to your php.ini:

apc.shm_segments=1
apc.optimization=0
apc.shm_size=128
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.enable_cli=1

Note: APC needs a temp path to exist, and be writable by the web server. It checks TMP, TEMP, USERPROFILE environment variables in that order and finally tries the WINDOWS directory if none of those are set.

4) copy apc.php (included with the .zip file) to directory on your web server and launch it.

You should see the following:

apc screen How to install Alternative PHP Cache

APC Cache options

Here is some more information about the various options that can be used to setup apc cache.

apc.enabled This can be set to 0 to disable APC. This is
primarily useful when APC is statically compiled
into PHP, since there is no other way to disable
it (when compiled as a DSO, the zend_extension
line can just be commented-out).
(Default: 1)

apc.shm_segments The number of shared memory segments to allocate
for the compiler cache. If APC is running out of
shared memory but you have already set
apc.shm_size as high as your system allows, you
can try raising this value.
(Default: 1)

apc.shm_size The size of each shared memory segment in MB.
By default, some systems (including most BSD
variants) have very low limits on the size of a
shared memory segment.
(Default: 30)

apc.optimization The optimization level. Zero disables the
optimizer, and higher values use more aggressive
optimizations. Expect very modest speed
improvements. This is experimental.
(Default: 0)

apc.num_files_hint A “hint” about the number of distinct source files
that will be included or requested on your web
server. Set to zero or omit if you’re not sure;
this setting is mainly useful for sites that have
many thousands of source files.
(Default: 1000)

apc.ttl The number of seconds a cache entry is allowed to
idle in a slot in case this cache entry slot is
needed by another entry. Leaving this at zero
means that your cache could potentially fill up
with stale entries while newer entries won’t be
cached.
(Default: 0)

apc.user_ttl The number of seconds a user cache entry is allowed
to idle in a slot in case this cache entry slot is
needed by another entry. Leaving this at zero
means that your cache could potentially fill up
with stale entries while newer entries won’t be
cached.
(Default: 0)

apc.gc_ttl The number of seconds that a cache entry may
remain on the garbage-collection list. This value
provides a failsafe in the event that a server
process dies while executing a cached source file;
if that source file is modified, the memory
allocated for the old version will not be
reclaimed until this TTL reached. Set to zero to
disable this feature.
(Default: 3600)

apc.filters A comma-separated list of POSIX extended regular
expressions. If any pattern matches the source
filename, the file will not be cached. Note that
the filename used for matching is the one passed
to include/require, not the absolute path. If the
first character of the expression is a + then the
expression will be additive in the sense that any
files matched by the expression will be cached, and
if the first character is a – then anything matched
will not be cached. The – case is the default, so
it can be left off.
(Default: “”)

apc.enable_cli Mostly for testing and debugging. Setting this enables APC
for the CLI version of PHP. Normally you wouldn’t want to
create, populate and tear down the APC cache on every CLI
request, but for various test scenarios it is handy to be
able to enable APC for the CLI version of APC easily.
(Default: 0)

apc.max_file_size Prevents large files from being cached.
(Default: 1M)

apc.stat Whether to stat the main script file and the fullpath
includes. If you turn this off you will need to restart
your server in order to update scripts.
(Default: 1)

apc.write_lock On busy servers when you first start up the server, or when
many files are modified, you can end up with all your processes
trying to compile and cache the same files. With write_lock
enabled, only one process at a time will try to compile an
uncached script while the other processes will run uncached
instead of sitting around waiting on a lock.
(Default: 1)

apc.rfc1867 RFC1867 File Upload Progress hook handler is only available
if you compiled APC against PHP 5.2.0 or later. When enabled
any file uploads which includes a field called
APC_UPLOAD_PROGRESS before the file field in an upload form
will cause APC to automatically create an upload_
user cache entry where is the value of the
APC_UPLOAD_PROGRESS form entry.
(Default: 0)

The offical PHP manual page can be found here.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

June 9, 2009   4 Comments