Hey guys, Happy Friday!
I know Drupal can already capture the IP address of a computer, because it comes through in messages sent from a Webform form. However, I need to capture and send the IP address when a purchase is completed in Ubercart. I need the IP address to be included in the email that is sent to the store owner. How can this be done? Thanks in advance!


i25’s picture

Any suggestions guys? Thanks.

awesome_cricket’s picture

"this is a question for the ubercart website forums,"

wait long enough, someone will say that to you. unfortunately i cannot offer any help with your question, but i hope someone can.

likely, you could include a hidden ip address line in the code which sends emails when ubercart is used. i don't use UC yet. i have it ready, but am not ready to explore the system yet. it shouldn't be very hard at all though, especially if it offers the option to send an email to begin with, because adding an ip address is just one line of extra code, usually.

awesome_cricket’s picture

<input type=hidden name=ip value="<?php echo @$REMOTE_ADDR; ?>">

something like this would help, if you knew which file you had to edit. one line of code.

i25’s picture

Thanks awesome_cricket.

Does anyone know what file I need to add this line in? I'm trying to print the IP address in the email that is sent to the store owner/admin when an order is completed. Thanks.

awesome_cricket’s picture

i'm keepin my eye on this thread, when i have time i'll see what i can do to help. in the meantime, i hope someone joins in.

i25’s picture

So I looked at the webform-mail.tpl.php file to see what code is printing the IP address and I found this in the file:
<?php print ($email['html'] ? '<p>' : '') . t('Submitted by anonymous user: [%ip_address]') . ($email['html'] ? '</p>' : ''); ?>
So I added this line to the admin.tpl.php file, but when I get the admin email, it prints out literally as IP Address: [%ip_address]. What do I need to do to get it to print out the actual IP address, just like the webform email? Thanks.

i25’s picture

Anything guys?

i25’s picture

Anything guys? This has to be easy for someone in this forum! :-)

mcfilms’s picture

This is a question for the ubercart website forums.

Naw, just kidding. But seriously, I don't think this is all that easy. The best method I can think of is to try tokens. The token for the user's ip is [current-user:ip-address].

But when I looked into it a bit further I see that user tokens might not pass into ubercart. So then it led me to have a look at this page which talks about integrating webforms into ubercart:
See http://drupal.org/node/908224

It looks like that solution may work, but I'm sure there are any hour of trial and error to be done. At least you are on the right path.

Good luck!

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

i25’s picture

Lol. Hey mcfilms. I did post the question in the ubercart forums as well, and I got a suggestion yesterday, which was to use this line:

<?php print $_SERVER['REMOTE_ADDR']; ?>.

I tried this and it worked perfectly! Thanks for your suggestions.


awesome_cricket’s picture

glad to see it worked out for you. i knew it would be simple.

your solution, almost identical to mine. it's all in that remote_address variable.

<?php print $_SERVER['REMOTE_ADDR']; ?>.

<input type=hidden name=ip value="<?php echo @$REMOTE_ADDR; ?>">
Waen’s picture

Does it work with proxy?
I guess if someone use a proxy it will give the proxy IP not the user IP?

MakeOnlineShop’s picture

Hello, can you confirm where to add this code ?

Thank you.