Recording IP address in osCommerce

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]’currency_value’ => $order->info[‘currency_value’]);[/php]

Change to:
[php]’currency_value’ => $order->info[‘currency_value’],
‘ip_address’ => tep_get_ip_address());[/php]

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]

[/php]

Add this line of code directly underneath it:
[php]

[/php]

Find:
[php]$orders_query_raw = “select o.orders_id …………[/php]

Change to:
[php]$orders_query_raw = “select o.ip_address, o.orders_id ………..[/php]

This is repeated another two times.

Find:
[php]

[/php]

Add this line of code directly underneath it:
[php]

[/php]

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

Simply add this piece of code:
[php]define(‘TABLE_HEADING_IP_ADDRESS’, ‘IP Address’);[/php]

Step 4: Database changes

Run this SQL file to amend your database to allow it to record the IP address;
[php]ALTER TABLE `orders` ADD `ip_address` VARCHAR( 20 ) NOT NULL;[/php]

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 Replies to “Recording IP address in osCommerce”

  1. 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

  2. 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

  3. 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.

  4. 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?

  5. 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

  6. 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.

  7. 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…

Leave a Reply

Your email address will not be published. Required fields are marked *