Monday, 31 October 2011

HSBC API: PayerTxnId is not in a valid base64 encoding

That pesky HSBC API caused me a lot of grief when I first had to set it up on a client site. For various reasons I ended up using the XML method of performing the transaction.

Having recently implemented the 3D secure (Payer Authentication Specification (PAS)) I was getting a PayerTxnId 'LOADS_OF CHARS' is not in a valid  base64 encoding. The PayerTxnId is pulled from the posted data from HSBC. It comes from the XID field.

It took me a while to spot it and, to be honest, I thought I would have to contact HSBC technical support yet again (who , by the by, are very good). But I did spot it! There was a space in the string. I swapped that out for a + and hey presto, the HSBC API processed it just fine.

Wednesday, 19 October 2011

Block IP Addresses on Windows Server 2003

A big thank you goes out to CodeHill today for allowing me to find out how to easily block IP addresses with built-in Windows server functionality.

The idea is that you create an IP Security Policy on the server and add each IP, range or subnet to it. Perfect :)

Tuesday, 18 October 2011

Unicode Characters in an Email Subject using PHP and PEAR

I've been working on a PHP site recently where I have had to cater for all languages and more importantly Unicode languages.

So after quite a lot of messing about and hunting around I found that I needed to do the following with the subject:

if (function_exists("mb_internal_encoding"))
if (function_exists("mb_encode_mimeheader"))
 $subject = mb_encode_mimeheader($subject, "UTF-8", "B", "\n");

Obviously if you know if the mb_* functions are available, then you can do away with the if statements.

This works using the PEAR Mail_Mime library. I haven't tested it with the built-in PHP mail function. I would assume it does not work.

Tuesday, 4 October 2011

How To Reset an Identity Column in MSSQL / SQL Server

Something I often find myself needing to do is reset the identity column on auto incrementing field in MS SQL / SQL Server.

There are a couple of ways of doing it:
  1. If you are emptying the table, instead of using a DELETE, use a TRUNCATE. That will automatically reset the identity.
  2. The ID can be set to a specific number by using DBCC CHECKIDENT([TABLE_NAME], RESEED, n). Where n is the number that is to be set.
If you already have data in the table and you want to make sure that the sequence is followed, then use this: