About Club osCommerce

Showcasing osCommerce - the good, the bad and the ugly!

StumbleUpon It! DIGG It!

Recording IP address in osCommerce

Written By Gary on Jul 14 2008 ·

Alan asks;

Is it possible to record the ip address of each sale?

Alan, yes it is. But it is not standard osCommerce procedure to do so.

Adding an IP address recorder is really easy and is a simple modification that amnyone, and I mean ANYONE can make. There is a couple of IP contributions available already, but I thought it would make a decent tutorial for anyone wanting to get a bit "technical" with osCommerce.

The three files that we will be amending are;

  • checkout_process.php
  • admin/orders.php
  • admin/includes/languages/english/orders.php

and we will be amending the orders table in the database to record the IP address.

Step 1: checkout_process.php

This file does the grunt work of recording orders made, so we need to add 1 line of code as so;

Find:

PHP:
  1. 'currency_value' => $order->info['currency_value']);

Change to:

PHP:
  1. 'currency_value' => $order->info['currency_value'],
  2. 'ip_address' => tep_get_ip_address());

Step 2: admin/orders.php

This files shows the orders made, we need to add a few pieces of code to this file.

Find:

PHP:
  1. <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_DATE_PURCHASED; ?></td>

Add this line of code directly underneath it:

PHP:
  1. <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_IP_ADDRESS; ?></td>

Find:

PHP:
  1. $orders_query_raw = "select o.orders_id ............

Change to:

PHP:
  1. $orders_query_raw = "select o.ip_address, o.orders_id ...........

This is repeated another two times.

Find:

PHP:
  1. <td class="dataTableContent" align="center"><?php echo tep_datetime_short($orders['date_purchased']); ?></td>

Add this line of code directly underneath it:

PHP:
  1. <td class="dataTableContent" align="center"><?php echo $orders['ip_address']; ?></td>

Step 3: admin/includes/languages/english/orders.php

Simply add this piece of code:

PHP:
  1. define('TABLE_HEADING_IP_ADDRESS', 'IP Address');

Step 4: Database changes

Run this SQL file to amend your database to allow it to record the IP address;

PHP:
  1. ALTER TABLE `orders` ADD `ip_address` VARCHAR( 20 ) NOT NULL;

That is it. If you have correctly made the changes, the buyers IP address will be recorded and will show in the order summary screen.


Buy Gary A Beer?
Buying me a "beer" helps me to keep my contributions updated and keep this blog alive. Cheers!


1 Comment

  1. Nice and thanks a lot

    Comment by john — July 20, 2008 @ 10:03 pm


Leave a comment

RSS feed for comments on this post · TrackBack URL

Hot 100 osCommerce Shops

View the osCommerce HOT 100These are the best looking, most exceptional osCommerce Stores as voted for by you.

New to osCommerce - get inspiration from these beautiful shops. Reckon your site has what it takes to become a member of the HOT 100? Submit it!