|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
How do I display the IP address of a visitor to my web-site using Perl CGI scripts?
-- Steven Coutts work@stevencoutts.org.uk |
|
#2
|
|||
|
|||
|
use $ENV{REMOTE_HOST} OR $ENV{REMOTE_ADDR} and check http://www.devshed.com/Talk/Forums/...TML/000177.html
------------------ Good luck, Bas ------------------ E-mail me at: b.vandermeijden@pecoma.nl |
|
#3
|
|||
|
|||
|
Ok I use this code right -:
$ip = $ENV{'REMOTE_ADDR'}; $n = `nslookup $ip | grep Name`; chop($n); $host = substr($n, rindex($n, " ")+1); if ($host eq "") { $host=$ENV{'REMOTE_ADDR'}; } I take it this will be in a file in the cgi-bin directory called say ip.cgi Now how do include this in my html file so it displays the IP? Obviously I need some kind of output statement in the script too. |
|
#4
|
|||
|
|||
|
##http://www.domain.com/cgi-bin/ip.cgi##
#!/usr/local/bin/perl $ip = $ENV{'REMOTE_ADDR'}; $n = `nslookup $ip | grep Name`; chop($n); $host = substr($n, rindex($n, " ")+1); if ($host eq "") { $host=$ENV{'REMOTE_ADDR'}; } print "Content-type: text/htmlnn"; print "Host: $host<br>n"; print "IP: $ip<br>n"; exit; ##http://www.domain.com/myfile.html## <html> <body> <!--#include virtual="/cgi-bin/ip.cgi" --> </body> </html> |
|
#5
|
|||
|
|||
|
Cheers exactly what I needed.
|
|
#6
|
|||
|
|||
|
I'm now trying to store these in hidden values on the page using the following appended to the end of the script.
print "<input type="hidden" name="ip" value="$ip">n" Now I realise the problem I am having stems from the quotes used in the print statement, how is it I overcome this? |
|
#7
|
|||
|
|||
|
Backslash the quotes: print "<input type="hidden" name="ip" value="$ip">n" Have fun. |
|
#8
|
||||
|
||||
|
freebsd knows his stuff, so use that example, or you could do it using CGI:
#!/usr/local/bin/perl use CGI; my $query = new CGI; print $query->header; print $query->remote_host; exit; [This message has been edited by tron (edited September 27, 2000).] |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Remote IP Address |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|