Link to home
Create AccountLog in
Avatar of mkido
mkido

asked on

How do I find a WEB-visitor's IP address?

Hello!   Everyone,

This is a second step of Country-Language automatic correllation (redirection) WEB page development.    I learned from Experts-Exchange, that with IP_to_Country General Public Lisence Table, I can figure out from IP number to a country.    

Now, when a WEB-surfer visits a site, I want to detect the surfer's IP number.   I think there is a way to do it.   For example, my business WEB-hit log shows all IP number or Domain Name of all surfers(visitors) in the hit log-table.    But I didn't design that WEB-hit log table, but my contracted ISP programmed it.   So, please let me know (help me), how to figure it out?   Thanks.
ASKER CERTIFIED SOLUTION
Avatar of hkey_current_user
hkey_current_user

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of mkido
mkido

ASKER

Thank you, hkey_current_user!

PHP and MySQL are getting very popular, and I'd better to get started.   I only use PERL for all my CGIs up to now.   Could you translate the simplest PERL code below to the PHP code.   Then I may able to get started.

In PERL

#! /usr/local/bin/perl

print "Hello! world!\n";

How does this go in PHP?   PHP is a kind of PERL like script language?   How about in mySQL?   Or any PHP book you learned useful?   Thanks.
Print is written in php more or less the exact same way ;)
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of mkido

ASKER

Hello!   Everyone.    

I got one book of PHP/MySQL and then I am getting understand that how PHP works.   It is very similar with PERL.   One moment, I will try out some suggested codes.  
Avatar of mkido

ASKER

Dear silionbrit,

I tried your codes in PERL-CGI, and it prints my ISP's environmental variable perfectly.   By the way what is

  "<tt>\n"      in front of    foreach-loop ??

And another question is, by using PERL-cgi, is there a convenient way to put it your PERL code at the main "index.html" page at main WEB access site.   In order to see who (which IP address) is visiting.   My impresssion is that PHP (hkey_current_user) may be convenient to handle this job.    Thank you for your comments!

SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of mkido

ASKER

Thank you, siliconbrit !!

I just got "PHP Cooking", and also am getting static IP Internet at home.    So, let me try now on.   Let me back to here for my feedback a little later.  

OK, while you are waiting for a static IP, you can use a free dynamic DNS service to point to your dynamic IP address at home:

   http://www.dyndns.org

If you use a router, most have the ability to register your IP address with the Dynamic DNS service when it changes.  If you don't, then there's plenty of software you can install on your workstation to do the same job.  Here's a perl method:

   http://www.dyndns.com/support/kb/archives/using_ddclient_with_dyndns_services.html

Good Luck.
Avatar of mkido

ASKER

Hello!    

My static IP is working at my home for PC, Macintosh, Linux (Fedora).   I am looking carefully all of your codes now.      Thank you about Dynamic DNS.      I found PHP is very interesting approach, combining PERL and HTML approaches.    
Avatar of mkido

ASKER

PERL appraoch is successul on my "www.tunefind.net", and here is the IP address and environment returns.

Codes from "siliconbrit,"
#!/usr/local/bin/perl

   print "Content-type: text/html\n\n";
   print "<tt>\n";
   foreach $key (sort keys(%ENV)) {
      print "$key = $ENV{$key}<p>";
   }


My local Internet Service Provider is on a DSL service.



CB_CODE = 1

CB_SLOT = 0

DOCUMENT_ROOT = /web

GATEWAY_INTERFACE = CGI/1.1

HOME = /

HTTP_ACCEPT = text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1

HTTP_ACCEPT_CHARSET = ISO-8859-1,utf-8;q=0.7,*;q=0.7

HTTP_ACCEPT_ENCODING = gzip,deflate

HTTP_ACCEPT_LANGUAGE = en-us,en;q=0.5

HTTP_CONNECTION = Keep-Alive, keep-alive

HTTP_HOST = www.tunefind.net

HTTP_KEEP_ALIVE = 300

HTTP_PROXY = 207.155.248.9

HTTP_PROXY_IP = 216.66.233.30

HTTP_REFERER = http://www.tunefind.net/HTM/call51.html

HTTP_USER_AGENT = Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031030

LOCALDOMAIN = tunefind.net

LOGNAME = cgiuser

MANPATH = /usr/man

PATH = /bin:/usr/vde/bin:/usr/local/bin:/usr/gnu/bin:/usr/ucb:/usr/ccs/bin:/usr/local/cvbin

PWD = /cgi/TEST

QUERY_STRING =

REMOTE_ADDR = 216.66.233.30

REMOTE_HOST = host-216-66-233-30.lcinet.net

REQUEST_METHOD = GET

SCRIPT_NAME = /cgi/TEST/cgi51.pl

SERVER_ADMIN = www@www.tunefind.net

SERVER_NAME = www.tunefind.net

SERVER_PORT = 80

SERVER_PROTOCOL = HTTP/1.0

SERVER_SOFTWARE = ConcentricHost-Ashurbanipal/1.8 (XO(TM) Web Site Hosting)

SHELL = /usr/local/bin/perl

TZ = EST5EDT

USER = cgiuser

VDE_CB_GRENT = chost

VDE_CB_PROD_NAME = XO(TM) Web Site Hosting

VDE_CB_SIGNUP_PATH = CNC

VDE_CB_TLD = cnchost.com

VDE_DOMAIN = tunefind.net

VDE_INBOUND = vrun:httpd

VDE_LOGNAME = cgiuser@tunefind.net

VDE_PGRPID = 19298

VDE_VERSION = 1.9d (clock)

VDE_ZONE = /cgi/

Avatar of mkido

ASKER

When I am on Comcast's Cable service,

CB_CODE = 1

CB_SLOT = 0

DOCUMENT_ROOT = /web

GATEWAY_INTERFACE = CGI/1.1

HOME = /

HTTP_ACCEPT = application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1

HTTP_ACCEPT_CHARSET = ISO-8859-1,utf-8;q=0.7,*;q=0.7

HTTP_ACCEPT_ENCODING = gzip,deflate

HTTP_ACCEPT_LANGUAGE = en-us,en;q=0.5

HTTP_CONNECTION = Keep-Alive, keep-alive

HTTP_HOST = www.tunefind.net

HTTP_KEEP_ALIVE = 300

HTTP_PROXY = 207.155.248.18

HTTP_PROXY_IP = 24.30.101.79

HTTP_REFERER = http://www.tunefind.net/HTM/call51.html

HTTP_USER_AGENT = Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax;nscd1)

LOCALDOMAIN = tunefind.net

LOGNAME = cgiuser

MANPATH = /usr/man

PATH = /bin:/usr/vde/bin:/usr/local/bin:/usr/gnu/bin:/usr/ucb:/usr/ccs/bin:/usr/local/cvbin

PWD = /cgi/TEST

QUERY_STRING =

REMOTE_ADDR = 24.30.101.79

REMOTE_HOST = c-24-30-101-79.hsd1.ca.comcast.net

REQUEST_METHOD = GET

SCRIPT_NAME = /cgi/TEST/cgi51.pl

SERVER_ADMIN = www@www.tunefind.net

SERVER_NAME = www.tunefind.net

SERVER_PORT = 80

SERVER_PROTOCOL = HTTP/1.0

SERVER_SOFTWARE = ConcentricHost-Ashurbanipal/1.8 (XO(TM) Web Site Hosting)

SHELL = /usr/local/bin/perl

TZ = EST5EDT

USER = cgiuser

VDE_CB_GRENT = chost

VDE_CB_PROD_NAME = XO(TM) Web Site Hosting

VDE_CB_SIGNUP_PATH = CNC

VDE_CB_TLD = cnchost.com

VDE_DOMAIN = tunefind.net

VDE_INBOUND = vrun:httpd

VDE_LOGNAME = cgiuser@tunefind.net

VDE_PGRPID = 3861

VDE_VERSION = 1.9d (clock)

VDE_ZONE = /cgi/

Avatar of mkido

ASKER

Thus, REMOTE_ADDRs are,
  DSL connection :  216.66.233.30
  Cable connection:  24.30.101.79

They are correct and accurate.   However, I haven't success on "index.php" approach.   The "www.tunefind.net" 's Server didn't respond.    I am not sure my side of error or the Server's setting.   Let me do one more trial.
Avatar of mkido

ASKER

By the way, I saw two dots in PHP codes around in the following.   Are they grammatical things?

 . $_SERVER{'REMOTE_ADDR'} .

I failed anyway by this PHP approach.   Thank you very much, I will close this post soon.

The dot means contatenate the strings, so:

  $str1="hello"
  $str2="world"


  $helloworld= $str1 . " " . $str2;

This means add "hello" to " " and then to "world", to form the string "hello world"

Avatar of mkido

ASKER

Thank you, hkey_current-user and siliconbrit.  

Finally I am getting into PHP and MySQL.   And it takes time.   I can feed back more quick, once I will have the basics.   Bye now.