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 · Comments (14)

Buy Gary A Beer?
Buying me a "beer" helps me to keep my contributions updated and keep this blog alive - and you get a link from my homepage to your site. Cheers!


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.

14 Comments

  1. Nice and thanks a lot

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


  2. After running the script, a column ip_adress is added to the data bases.
    However the ip adress is not recorded and running the checkout_process.php gives the following error:
    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/beashobbyp/domains/beashobbyplaneet.nl/public_html/checkout_process.php on line 96

    Line 96 is: 'ip_address' => tep_get_ip_address())

    Am I doing something wrong?
    Who can help me out.
    Thanks,
    Nico

    Comment by Nico — June 29, 2009 @ 7:56 pm


  3. You have made a mistake in following the code – line 96 has a semi-colon.

    Comment by Gary — June 30, 2009 @ 8:56 am


  4. Sorry, my mistake, copy and/or pasted it wrong.

    'currency' => $order->info['currency'],
    'currency_value' => $order->info['currency_value'])
    'ip_address' => tep_get_ip_address());

    Can someone help me out?

    Regards,
    Nico

    Comment by Nico — June 30, 2009 @ 6:51 pm


  5. Nico – can you not see the error here? Look again!

    You will need to know at least some PHP in order to make progress with oscommerce.

    Comment by Gary — July 1, 2009 @ 12:10 pm


  6. Got it working now!

    Comment by Nico — July 8, 2009 @ 10:27 pm


  7. i also get same error.
    what is must be changed or edit?
    Nico…what you done so you php working?

    Comment by Pande — July 14, 2009 @ 10:19 am


  8. done! wrong string…:)

    Comment by Pande — July 14, 2009 @ 10:24 am


  9. I made the above changes, but it seems the ip address is not recorded in the database although the ip_address entry is in the order-table.

    Any help?

    Comment by PmgR — August 5, 2009 @ 5:44 am


  10. Hi PmgR – should work just fine, so go over the instructions once again. I am happy to quote you for an install shold you need me to do so. Cheers, Gary

    Comment by Gary — August 10, 2009 @ 9:00 am


  11. I have added this in.
    How would I go about adding the IP of a customer on the email confirmation that is sent to admin.
    Thanks in advance.

    Comment by Terry — October 2, 2009 @ 8:08 pm


  12. Terry – which email that goes to Admin? Did you mean the copy of a sale order?

    Also – your site is ripe for a makeover! Could make it really special…

    Comment by Gary — October 4, 2009 @ 10:12 pm


  13. I SEE LIKE ALL IS WORKING, BUT I CAN'T SEE THE IP IN THE ORDERS, ANY HELP ?

    Comment by RAFAEL — December 17, 2009 @ 12:54 am


  14. Hi, means you have not followed install instructions properly. Try again.

    Comment by Gary — December 18, 2009 @ 11:04 am


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!