Tag Archives: php

Atomic Operations in MySQL–How to wrap Inserts or Updates into a Transaction

18 Feb

innodb-vs-myisam-300x225As a developer, it is normally quite un-nerving to get a call from the people using your beautifully designed software with the message – things have gone wrong and your code or system has gone fritzzz… I normally just blame the operators cum users of the system for either not using the system right or for putting in wrong inputs. I know – as developers, we are supposed to code as if the users are total and absolute idiots but from time to time, the crazy things that users put as inputs on systems just catches us off guard as anybody in their right mind would never have put ‘that’ as an input.

You would be surprised how many times people call, and when the customer care clerk asks the user for their usernames so that their account can be located and looked into – the person needing help on the other side of the line says “Let me text you my username”. The reason as to why some one would use the term bi*** as their username on a public site is beyond me. I digress, back to the topic.

Continue reading

Advertisements

Block or Allow access to PHP script based on remote IP and CIDR list

25 Jun

400px-CIDR_Address Spam…we all hate it. It is nice when things like reCaptcha and Asimet work but these Chinese have a way of bypassing those spam filters and then fill your blog or website with useless comments and fake registrations. So, how about a way to just block all ip addresses coming from a specific region from viewing your registration page or comment box? Well…find below some steps to follow to do exactly that.

Continue reading

Crontab Log – How to log the Output of a Cron Script (and email it as well)

28 Feb

cron-logo-680x225 As mentioned earlier, in my world of development, I keep landing myself into sticky situations and what makes me keep my job or clients happy is that I get myself out of such sticky situations quick quickly. Now, the situation I encountered recently involved crons

I have a php script whose function is to check a certain database for messages to be sent. The script should then collect required messages and pass them on the the Goip SMS gateway. Now, how do I save the output of the sending to the gateway so that I can know which ones failed – if any – without having to add the logging function into the sending script and without having to look through cron’s own logs? Answer – simply tweak the cron command slightly to achieve logging.

Continue reading

Import CSV to MySQL using PHP

28 Feb

In my course of work, I normally come across many small problems that I am asked to solve and here is one of the simpler ones. The following code is for developers looking for an easy way to import a comma separated values (CSV) file into a mysql database via PHP. The code below adds contacts from an uploaded CSV file into a MySQL table, populating three fields (name, email, phone) Continue reading

Free PesaPal Payment Plugin Virtuemart 2.0 (Joomla 1.5/1.6/1.7/2.5/3.0)–Update 1

31 Dec

It is becoming aparent that I do some of my best work on the eves of holidays. So, it is new years eve, and here we go with an update to the Virtuemart + Pesapal plugin that I published on Christmas eve.

It came to my attention that Pesapal actually have an official plugin for virtuemart 2.0. I suppose, the more, the merrier. The only problem is for my test in Joomla 2.5 and latest virtumart, the plugin does not work. I also found quite a few issues it you have their plugin and my plugin installed. These therefore are the issues I am addressing in this update.

Changelog:
  • Added default image for pesapal upon installation of plugin
  • Changed name of plugin to btgpesapal to avoid conflict with Pesapal’s official plugin
  • Added check for shared php classes oauth and xmlhttprequest just incase another installed plugin is already implementing them thus preventing re-delaration errors
  • Added sys.ini language file for use on the front end of the Virtuemart shopping cart.
  • Added btgpesapal folder during installtion to avoid placing class files in root of plugin folder.
Tested On:
- Virtuemart v2.0.14
- Joomla v2.5.8
- PHP v5.3.10 & MySQL v5.5.20

DOWNLOAD VERSION 2.1

Continue reading

Free PesaPal Payment Plugin Virtuemart 2.0 (Joomla 1.5/1.6/1.7/2.5/3.0)

24 Dec

Its been a while since I have given out free code. Not that I have not been developing. On the contrary, I think I have been developing a bit too much, causing me to forget to give back to the community that helps me develop in the first place.

It is Christmas Eve, and the world should have ended three days ago – according to the Myans. Now that we are all still here, well, I suppose it is time I release this plugin that I have had in my archive for quite a while, but simply had not gotten the time to publish it on the site. So here goes.

Tested On:
- Virtuemart v2.0.14
- Joomla v2.5.8
- PHP v5.3.10 & MySQL v5.5.20

DOWNLOAD VERSION 2.0

Continue reading

Auto-Capitalize using JavaScript

21 Nov

I help in running and continuously improving a classifieds website. Now, the problem is that for sites that are that public and with a generally public audience, you get all kinds of inputs, legitimate and otherwise. Every so often, to make things work and look like they should, some idiot-proofing is required. So, find below a script you can use to auto-capitalize input like I had to for my listing titles across the sites I am involved in.

Lets assume a simple form like the one below…

Continue reading