Click to See Complete Forum and Search --> : IP sent by email


kareem
02-14-2003, 03:42 PM
Hi folks,
I wonder if someone can tell me a code that I can embeded on my website so that when a visitor comes to the site, the visitor's IP is sent to me by email.
Is it possible?
Thanks

khalidali63
02-14-2003, 03:56 PM
You can not do that with JavaScript.
You will have to use Java or some other programming language.

Cheers

Khalid

kareem
02-14-2003, 04:33 PM
What about a botton when clicked, it sends me some information about the visitor just like what we see when we view the email headers.

khalidali63
02-14-2003, 04:40 PM
The best you can do is get the URL of the page.
For any thin system specific you have to turn to hard corre programming languages.
SOm of the gentlmen here are perl and php experts (e.g pyro and charles) they might be able to help you on that if your ISP allows you to use those scripting languages.

cheers

Khalid

Zach Elfers
02-14-2003, 04:41 PM
If you used Perl or some language like that you could do this. There is a CGI place on these forums. Maybe you could get better answers there. I do not know Perl so don't ask me. I just know that it should work for what you want.

pyro
02-14-2003, 04:54 PM
Here is the PHP version.

Make a file called sendip.php
<?PHP
if ($sendip)
{
$ip = $REMOTE_ADDR;
mail("you@yourdomain.com", "A user with the IP address of $ip has visited your site","Hello!\n\nA user with the IP address of $ip has visited your site.", "from: New Visitor\r\n");
}
?>

<form action="sendip.php" method="post">
<input type="submit" name="sendip" value="send your ip">
</form>

Or, if you want it to go automatically when a user enters the page

<?PHP
$ip = $REMOTE_ADDR;
mail("you@yourdomain.com", "A user with the IP address of $ip has visited your site","Hello!\n\nA user with the IP address of $ip has visited your site.", "from: New Visitor\r\n");
?>

kareem
02-14-2003, 04:58 PM
Thanks. Then where should I place the file? I do not know much about these matters.
Your help is highly appreciated

pyro
02-14-2003, 05:27 PM
Just place the file anywhere on your server and check if it works. Edit the script to send it to your email, and then try running it. If you get an email, your server is working correctly.

Then you can just copy the code into the page that you actually want to send the IP address from.

You may want to do something like this while you are testing:

<?PHP
$ip = $REMOTE_ADDR;
mail("you@yourdomain.com", "A user with the IP address of $ip has visited your site","Hello!\n\nA user with the IP address of $ip has visited your site.", "from: New Visitor\r\n");
echo ("An email was send with the ip address"); //you can delete this line after it is working.
?>

kareem
02-14-2003, 05:41 PM
Thanks for fast reply! After I edited the scrip and I replaced the dummy email by my email, I copied the file to a folder in my site and I accessed the folder couple times but nothing has been sent to me. In addition to sendip.php file, this folder contains another file called xxx.index. Do not I need to do something for the email? all I did was like this xxxx@xxxxxxx.net
what do you think? Did I make a something wrong?
Thanks

pyro
02-14-2003, 05:55 PM
I'm guessing your server doesn't support PHP. Try this simple test to check.

test.php<?PHP
echo ("I have PHP!");
?>

Let me know what this returns.

kareem
02-14-2003, 06:07 PM
If I understood righ! I made the test.php and download it to the website, the same folder, after i deleted the first file "sendip.php". I access the folder ... and nothing happened.
I was waiting for something to "pop-up" for example!
Does this mean that the server dose not support php or I might did somthing wrong ...
As I was advised by some folks here .... I should go wiht CGI ...I have no idea what the differecnes are... but once I did place a form on my website so the visitors can reach me .. and it worked just fine ...

pyro
02-14-2003, 10:31 PM
If you tried to access just the folder (ie. http://www.yourdomain.com/php) the file would need to be named index.php. Otherwise, you can link to it like this: http://www.yourdomain.com/yourfolder/test.php. Nothing is going to "pop up" it will just print I have PHP! to the screen

pyro
02-15-2003, 12:07 AM
I was going to give you a Perl version, but I see you've gotten your answer here. http://forums.webdeveloper.com/showthread.php?s=&threadid=4247

kareem
02-15-2003, 06:26 AM
Thank you Supreme Being... it really works...
Good man!

kareem
02-15-2003, 06:29 AM
Can I add the country code, date and time
Thanks

pyro
02-15-2003, 09:57 AM
Are you talking about the CGI or the PHP version?

pyro
02-15-2003, 10:38 AM
Here is the CGI version. Note that the location ($ENV{'TZ'}) does not work on all servers.

#!/usr/bin/perl

$mailprog = '/usr/sbin/sendmail'; # path to sendmail
$adminemail = "you\@yourdomain.com"; # emial address

$ip = $ENV{'REMOTE_ADDR'}; #ip address
$location = $ENV{'TZ'}; # location


# Define arrays for the day of the week and month of the year.
@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
@months = ('January','February','March','April','May','June','July','August','September','October','November', 'December');

# Get the current time and format the hour, minutes and seconds. Add
# 1900 to the year to get the full 4 digit year.
($second,$minute,$hour,$numberday,$month,$year,$textday) = (localtime(time))[0,1,2,3,4,5,6];
$time = sprintf("%02d:%02d:%02d",$hour,$minute,$second);
$year += 1900;

# Format the date.
$date = "$days[$textday], $months[$month] $numberday, $year at $time";

#Send email

open(MAIL,"|$mailprog -t");
print MAIL "To: $adminemail\n";
print MAIL "From: New Visitor\n";
print MAIL "Subject: New Visitor\n\n";
print MAIL "Hello!\n\nA user with the IP address of $ip has visited your site on $date\n\nThey are located in $location";
#print MAIL "They are located in $location\n";
close (MAIL);

#Print results to the page

print "Content type: text/html\n\n";
print "$ip\n";
print "$location\n";
print "$date\n";

kareem
02-15-2003, 05:09 PM
No am talking about php version. I was not able to do the CGI one. It seems somehow complecated.
The one works for me is the php scripts .. both of them worked fine.
I will give cgi a shot to see ..
Thanks

pyro
02-15-2003, 06:07 PM
Let me know if you need the PHP version of it. I'll try to get it to you... For the cgi version set the permissions to 755, and upload in ascii...

kareem
02-15-2003, 07:02 PM
First of all, I would like thank you for your great help. Second, I would like from you, if you wish, to recommend a referrence for learning php. I read about it and looks fun to learn.

I tried to do something like "HTML" thing, photo or something in the file index.php but I could not ... if I add somehting to the file, it won't work. I tried putting the script into the head of HTML file and include some cool think in the body ..but nothing work ...

I donot understand what you mean by "set the permissions to 755".

pyro
02-15-2003, 10:32 PM
Show me the file you were trying to use. It's possible you just have a simple error.

A great place to learn PHP would be http://www.php.net I would also recommend the book "PHP for the World Wide Web" to get you going on the basics. PHP is very fun, IMO. :D Another good place to get help on PHP is http://www.phpbuilder.com/board

By "setting the permissions to 755" I mean that you need to chmod the file to 755 on your server. I should think that any FTP program can do this...