CartMetrix - Do you know yours?

6/22/2007

Zencart Hack - Logout Customer Automatically After X Failed Payment Attempts

Credit card slamming is the practice of trying hundreds or thousands of card numbers and security code combinations to find the few in the batch that will actually work. I have discussed credit card slamming here and over at the ZenCart forums several times in the past.

The code snippet below can be used in modules/checkout_process.php to automatically log a user out after a set number (6 in the below snippet) of payment attempts.

// damonp add auto logoff after 6 attempts
if(! isset($_SESSION['payment_attempt'])) $_SESSION['payment_attempt'] = 0;
$_SESSION['payment_attempt']++;

if($_SESSION['payment_attempt'] > 6)   { // change 6 to change how many attempts to allow before logout
   // log attempt or email report 
   // the following information is useful
   // "Host:\t\t".$_SESSION['customers_host_address'].
   // "\nCustomer:\t".$_SESSION['customer_id'].
   // "\nTotal:\t\t".$_SESSION['cart']->total,
   // destroy session to log customer out
   zen_session_destroy();
   // redirect to timeout page or create new page to redirect to
   zen_redirect(zen_href_link(FILENAME_TIME_OUT, '', 'SSL'));
}

Place in between this code near the top of the file:

// if the customer is not logged on, redirect them to the time out page
  if (!$_SESSION['customer_id']) {
    zen_redirect(zen_href_link(FILENAME_TIME_OUT));
  }

INSERT AUTO LOGOUT FUNCTIONALITY HERE

// load selected payment module
  require(DIR_WS_CLASSES . 'payment.php');
  $payment_modules = new payment($_SESSION['payment']);
// load the selected shipping module
  require(DIR_WS_CLASSES . 'shipping.php');

I found six attempts to work well on the sites I implemented on. You do not want to adversely impact normal users but you do want to make it harder on abusers so that they just go away.

BE WARNED

Improper use of this code could prevent anyone from checking out. The two things that will save you when trying this out are:

  1. MAKE A BACKUP
  2. FULLY TEST BEFORE CALLING IT COMPLETE

Popularity: 22%

CodeIgniter and BambooInvoice

I recently started toying around with CodeIgniter on a new project where I need a simple user login and administration system. I was initially attracted to the first two features listed:

  1. You want a framework with a small footprint.
  2. You need exceptional performance.

This is the first framework I have ever stayed with after a day because it didn’t feel constricting.

CodeIgniter is an open source Web Application Framework that helps you write kick-ass PHP programs.

While looking at the products made with CodeIgniter I found this cool invoicing application:
BambooInvoice: Simple, Open Source, Online Invoicing

Works very similarly to Blinksale buy you own it and can fully customize it. If I only had time to customize it… I think for now Blinksale will work for me.

Popularity: 14%

4/9/2007

Wordpress Hack to Debug Themes on a Live Site

How can a Wordpress them be debugged privately without showing the wizard behind the curtain to everyone else? This simple hack will use the specified theme only for one remote IP... yours. This can be used when creating a new theme by configuring Wordpress to present the original theme and specifying your new theme in development in place of THEME_NAME below. Also replace YOUR_IP_ADDR with your local IP address. THEME_NAME must be an existing theme directory in wp-content/themes/.

To debug an existing theme, copy your theme directory to a new directory under /themes/ (maybe THEME_NAME-dev). Leave Wordpress configured to serve the original theme at THEME_NAME and configure the hack to serve THEME_NAME-dev to your IP address.

Edit wordpress/wp-includes/theme.php as below:

Before

function get_template() {
   return apply_filters('template', get_option('template'));
}

After

function get_template() {
if($_SERVER['REMOTE_ADDR'] == 'YOUR_IP_ADDR')   {
   return 'THEME_NAME';
}
   return apply_filters('template', get_option('template'));
}

Depending on how the template links to it's stylesheet, the get_stylesheet() function (in the same file) may need a similar hack:

Before

function get_stylesheet() {
   return apply_filters('stylesheet', get_option('stylesheet'));
}

After

function get_stylesheet() {
if($_SERVER['REMOTE_ADDR'] == 'YOUR_IP_ADDR')   {
   return 'THEME_NAME';
}
   return apply_filters('stylesheet', get_option('stylesheet'));
}

This will not work with a private IP address like 192.168.x.x or 10.10.x.x. The IP must be the external address of your router or firewall. To find your external IP address use this link:
http://emailurl.com/myip

Also remember that if you change local IP addresses, you need to update the IP address configured in the snippet above. Most DSL/cable connections use a dynamic IP address that changes every few hours or daily.

Once the theme is good to go, merge the changes into the live template and comment out the code to disable the hack.

Popularity: 24%

3/10/2007

ZenCart Inventory Report - Updated

Thanks to Ron for posting a bug back on the Zencart forums about my Zencart Inventory Report

Fixed… download… enjoy.

Popularity: 21%

3/9/2007

Google Code Search

Bad code haunts you forever… Google Code Search

Popularity: 9%

2/23/2007

PHP Error - Parse error: syntax error, unexpected $end in

Parse error: syntax error, unexpected $end in ... on line ...

Don't you love it when the line number indicated for an error message is the last line in the file which obviously has no error? I spent twenty minutes on this one last night.

Check for unmatched braces, brackets, parentheses or PHP tags. Nope.

Try echoing line numbers to see where execution stops. In this case no output was generated even with an echo on line #1.

Create a new file and pasted the code as Unix ASCII. Still no change.

Check PHP settings. short_open_tag is disabled by default.

[root@atlas ~]# php -i | grep short_open_tag
105:short_open_tag => On => On

Create .htaccess file:

php_flag short_open_tag on

Page loads with no errors.

Do a search for short open PHP tags in the source and replace with default tags.

Find

<?

Replace

<?php

Turn short_open_tag back off in .htacess:

php_flag short_open_tag off

Page still loads with no errors.

Popularity: 36%

« Previous Page Next Page »


damonparker.org is proudly powered by WordPress
Entries (RSS) and Comments (RSS).

copyright © 2002-2008 damonparker.org. all rights reserved.

Close
E-mail It