Getting Visitors' IPs AND Avatar Names

Don Sam Stormrage
by Don Sam Stormrage · 46 posts
13 years ago in PHP
Posted 13 years ago · Author
Okay after loads and loads of tests and a huge amount of time I've spent making all of this work, I've finally done it!!! And I'm soooooooo happy :D It's such a good feeling lol sorry if I'm bugging :P Aaaanyway let's just get straight to the tutorial. This is a better and more useful version of Ghoku's IP catching tutorial, and of course, a CLEANER version.

Things You Will Need:

. Notepad (I recommend Notepad++)
. An IMVU account (of course)
. A webhost which provides PHP hosting and email service
. At least some basic knowledge of PHP and JavaScript

Step One:

Open up notepad and paste this script in it (I'll explain what it does):
Code
<?php
$ip = getenv(REMOTE_ADDR);
$avi = $_GET['AviName'];
mail("Your Email Address", "Your homepage visitor", "IP: ".$ip."\nAvatar: ".$avi);
?>


First off, remove the part with "Your Email Address" with your actual email address so that it emails it to you and the script works.

We declare a variable named "$ip" and tell it to store the value returned by the PHP function "getenv(REMOTE_ADDR);" which is the function in PHP to get the IP address. Keep in mind that we're dealing with two languages that are technically opposite to each other. PHP is server oriented, it works on servers only and performs server tasks. JavaScript is a client oriented language, it cannot deal with IP obtaining or other server related tasks.

Another variable declaration by the name "$avi" which has the return value of the function "$_GET['AviName'];" which is the easiest way to send information to a PHP document is by using the GET method, which appends information to the end of the URL as a parameter/argument (for example, "page.php?arg1=value"). PHP can access GET information by accessing $_GET[x], where x is a string containing the name of the argument. This is the most efficient method of passing variable values from JavaScript to PHP in my opinion.

The last one is pretty self explanatory. It's the PHP mail() function, whose first parameter is the email address to send the email to, the second is the subject and the third and last one is the actual body of the email message. Remember to always give parameters to this function in quotes (preferably double quotes).

Save the file with the name "get_info.php".

Step Two:

Sign up for a webhost which provides PHP hosting and email service or log in to your account if you already have an account with a host that provides those two things. Go to your file manager and put the file "get_info.php" into preferably the root dirctory, where the homepage of your website is present. It is actually the folder which is sometimes called "htdocs" or "public_html" or something like that. Upload the file and place it there. The URL to your "get_info.php" file would be as follows:

Code
http://www.yourwebsite.com/get_info.php


where "www.yourwebsite.com" replaces your website's address.

Step Three:

Go to your IMVU HP and edit one of the panels that have been set to visible. REMEMBER: it is important that the panel you are putting this script into is set to visible otherwise it won't work. Edit the HTML of the panel and put this script in it and save it:
Code
<script type="text/javascript">
    var ifr = document.createElement("iframe");
    var vName = document.getElementById("mininav-avname").innerHTML;
    ifr.src = "http://www.yourwebsite.com/get_info.php?AviName=" + vName;
    ifr.style.visibility = "hidden";
    document.body.appendChild(ifr);
</script>


Remember to replace the part "www.yourwebsite.com" with your actual website's URL. Right then, the first line declares a variable named "ifr" which contains an iframe element (it is built-in in JavaScript). The next line declares a variable named "vName" which contains the avatar name of the person who visits your HP. The next line directs the iframe to the get_info.php file with an argument "AviName" followed by putting in the value contained by the variable "vName".

Remember we used "$_GET['AviName']" in our PHP file? Well, that's what is being used here.

The second-last line simply makes the iframe invisible/hidden. The last line appends the created iframe to the body of the parent page.

To test, after saving, refresh your HP or preview it. It should send an email to you containing your IP address and your avatar name.

Any questions, complains and praise is welcome :D
Posted 13 years ago · Author
Don Von Free Credits wrote:
I will test it and post the results.

Thank you sir :D And I did test it with a few dummies and some proxies, they all worked as expected.
Posted 13 years ago
Nice! I will try it. :)
Posted 13 years ago · Author
DM wrote:
Very Nice. Did not work on one of my guest accounts though. Not sure why.

O_O worked on all of my visitors though ._.' maybe you haven't set the panel's setting to everyone? You have to make sure that the panel that you wrote the script in is visible at all times.

DM:
I put it in my wishlist panel which is set to everyone. The site I used to host the php file works fine. Tested another php file with it.
Last edited by DataMine on Wed Jan 21, 2015 4:47 am, edited 3 times in total.
Reason: Wrong edit by someone else. Sorted it now.
Posted 13 years ago · Author
Don Von Free Credits wrote:
Random load failure on the iframe?

Don Von, did you test it yourself?
Posted 13 years ago
Gonna try this it could be very usefull in future.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT