Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Customers IP and Geo Country info with order_confirmation email


Recommended Posts

Ok I made an error in my hook... carrying over code from the previous version that required edits to the order class.

	    global $order;
	  
	      $customers_ip = $order->customer['customers_ip'];

So, I have redone the hook to include its own query....

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Released under the GNU General Public License
*/

  class hook_admin_orders_location {

    function listen_orderTab() {
      global $_GET;

          $customer_ip_query = tep_db_query("select customers_ip from orders where orders_id = '" . (int)$_GET['oID'] . "'");
		  $customer_ip_raw = tep_db_fetch_array($customer_ip_query);		
		  $customers_ip = $customer_ip_raw['customers_ip'];
	  
          $tab_title = Location;
          $tab_link = substr(tep_href_link('orders.php', tep_get_all_get_params()), strlen($base_url)) . '#section_location_content';

          $geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$customers_ip"));

          $country = $geo["geoplugin_countryName"];
          $city = $geo["geoplugin_city"];
          $region = $geo["geoplugin_regionName"];
		  $latitude = $geo["geoplugin_latitude"];
		  $longitude = $geo["geoplugin_longitude"];

         
		 $output = <<<EOD
<script>
$(function() {
  $('#orderTabs ul').append('<li><a href="{$tab_link}">{$tab_title}</a></li>');
});
</script>

<div id="section_location_content" style="padding: 10px;">
 <p><strong>Customers Location: </strong>{$customers_ip}<br><br>{$country}<br>{$city}<br>{$region}<br>{$latitude}<br>{$longitude}</p> 
 
</div>
EOD;

      return $output;
    }
  }
?>
Link to comment
Share on other sites

@@burt, somewhat related question.... in my checkout_success content mod, to grab and store the customers IP address, you had suggested to use the built in function to get the IP.

   $customers_ip = tep_db_prepare_input(tep_get_ip_address());

In place of

    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = $_SERVER['REMOTE_ADDR'];
 
    if(filter_var($client, FILTER_VALIDATE_IP))
    {
        $ip = $client;
    }
    elseif(filter_var($forward, FILTER_VALIDATE_IP))
    {
        $ip = $forward;
    }
    else
    {
        $ip = $remote;
    }

Which I certainly understand.... however, have you noticed the built in function does not get IPV6 addresses?

 

I've noticed, by looking at "who's online", about 25% of customers online have a "blank" IP address... and now that I have moved this over to my live site also notice about 25% of the orders are have no IP.

 

I've drawn the conclusion - based on my original  code where 100% had an IP and about 25% of those IP's where IPV6 (I believe... example below)....

 

 

xxxx:1970:48e2:xx

 

Thoughts????

Link to comment
Share on other sites

Thoughts????

If you work with whats already there, then when core gets updated it automatically fixes itself. However as we all know, that can take a while.

 

Alternative is to make an inbuilt (in the module) function just for its own use... <--- this

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...