To Get And Show The IP via Javascript

Jesse

Active Member
Messages
1,360
Reaction score
0
Points
36
To Get And Show The IP via Javascript

To show the IP via JavaScript


var ip= '<!--#echo var="REMOTE_ADDR"-->';
document.write("Your IP Address is :"+ip+" ");
_______________________________________________

To show IP via ASP


request.ServerVariables("REMOTE_ADDR")
____________________________________
TO SHOW IP VIA PHP

Code:
<?
$remote_address = getenv("REMOTE_ADDR");
echo "Your IP address is $remote_address.";
$browser_type = getenv("HTTP_USER_AGENT");
echo "You are using $browser_type.";
?>
 

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
Dont use JAVASCRIPT

i don't get why not to use JS to find the ip address, I believe it is as good as using anything else to find the ip; ie PHP.
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
yeah...i don't think apoorav understands anything (lol)

:p

Great tut, i only knew the PHP version.
 

kkenny

Active Member
Messages
1,950
Reaction score
0
Points
36
Is getting the IP via Javascript just as effective as getting it via PHP or any other scripting language?
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
No, it is not, since the user can turn off javascript, plus, the only to store an IP found with JS is to use AJAX or submit a form. It is way more easier and faster to use a server-side method.
 

gptsven

New Member
Messages
253
Reaction score
5
Points
0
why all the hussle?

php code to print IP:

PHP:
<?php
$vistor_ip = $_SERVER['REMOTE_ADDR'];
echo "your IP-address is :" . $visitor_ip;
?>
 

shortdogmb

New Member
Messages
1
Reaction score
0
Points
0
Here's some php code to do it with.

<?php


echo "Your IP is";
echo $_SERVER["REMOTE_ADDR"];


function get_ip_address() {


// check for shared internet/ISP IP


if (!empty($_SERVER['HTTP_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_CLIENT_IP']))


return $_SERVER['HTTP_CLIENT_IP'];






// check for IPs passing through proxies


if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {


// check if multiple ips exist in var


$iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);


foreach ($iplist as $ip) {


if ($this->validate_ip($ip))


return $ip;


}


}






if (!empty($_SERVER['HTTP_X_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_X_FORWARDED']))


return $_SERVER['HTTP_X_FORWARDED'];


if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))


return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];


if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && $this->validate_ip($_SERVER['HTTP_FORWARDED_FOR']))


return $_SERVER['HTTP_FORWARDED_FOR'];


if (!empty($_SERVER['HTTP_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_FORWARDED']))


return $_SERVER['HTTP_FORWARDED'];






// return unreliable ip since all else failed


return $_SERVER['REMOTE_ADDR'];


}






function validate_ip($ip) {


if (filter_var($ip, FILTER_VALIDATE_IP,


FILTER_FLAG_IPV4 |


FILTER_FLAG_IPV6 |


FILTER_FLAG_NO_PRIV_RANGE |


FILTER_FLAG_NO_RES_RANGE) === false)


return false;


self::$ip = $ip;


return true;


}


?>
 

necpro

New Member
Messages
11
Reaction score
0
Points
0
Hello,

you can use :

<script language="JavaScript">
VIH_BackColor = "palegreen";
VIH_ForeColor = "navy";
VIH_FontPix = "16";
VIH_DisplayFormat = "You are visiting from:<br>IP Address: %%IP%%<br>Host: %%HOST%%";
VIH_DisplayOnPage = "yes";
</script>
<script language="JavaScript" src="http://scripts.hashemian.com/js/visitorIPHOST.js.php"></script>
 

sajjadhira

New Member
Messages
3
Reaction score
0
Points
1
I think this function is also a good soloution to find users real IP address.

function getrealip()
{
if (isset($_SERVER)){
if(isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
if(strpos($ip,",")){
$exp_ip = explode(",",$ip);
$ip = $exp_ip[0];
}
}else if(isset($_SERVER["HTTP_CLIENT_IP"])){
$ip = $_SERVER["HTTP_CLIENT_IP"];
}else{
$ip = $_SERVER["REMOTE_ADDR"];
}
}else{
if(getenv('HTTP_X_FORWARDED_FOR')){
$ip = getenv('HTTP_X_FORWARDED_FOR');
if(strpos($ip,",")){
$exp_ip=explode(",",$ip);
$ip = $exp_ip[0];
}
}else if(getenv('HTTP_CLIENT_IP')){
$ip = getenv('HTTP_CLIENT_IP');
}else {
$ip = getenv('REMOTE_ADDR');
}
}
return $ip;
}

This is Output
 

sajjadhira

New Member
Messages
3
Reaction score
0
Points
1
I think this function is also a good soloution to find users real IP address.

function getrealip()
{
if (isset($_SERVER)){
if(isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
if(strpos($ip,",")){
$exp_ip = explode(",",$ip);
$ip = $exp_ip[0];
}
}else if(isset($_SERVER["HTTP_CLIENT_IP"])){
$ip = $_SERVER["HTTP_CLIENT_IP"];
}else{
$ip = $_SERVER["REMOTE_ADDR"];
}
}else{
if(getenv('HTTP_X_FORWARDED_FOR')){
$ip = getenv('HTTP_X_FORWARDED_FOR');
if(strpos($ip,",")){
$exp_ip=explode(",",$ip);
$ip = $exp_ip[0];
}
}else if(getenv('HTTP_CLIENT_IP')){
$ip = getenv('HTTP_CLIENT_IP');
}else {
$ip = getenv('REMOTE_ADDR');
}
}
return $ip;
}

This is Output
 

sajjadhira

New Member
Messages
3
Reaction score
0
Points
1
I think this function is also a good soloution to find users real IP address.

function getrealip()
{
if (isset($_SERVER)){
if(isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
if(strpos($ip,",")){
$exp_ip = explode(",",$ip);
$ip = $exp_ip[0];
}
}else if(isset($_SERVER["HTTP_CLIENT_IP"])){
$ip = $_SERVER["HTTP_CLIENT_IP"];
}else{
$ip = $_SERVER["REMOTE_ADDR"];
}
}else{
if(getenv('HTTP_X_FORWARDED_FOR')){
$ip = getenv('HTTP_X_FORWARDED_FOR');
if(strpos($ip,",")){
$exp_ip=explode(",",$ip);
$ip = $exp_ip[0];
}
}else if(getenv('HTTP_CLIENT_IP')){
$ip = getenv('HTTP_CLIENT_IP');
}else {
$ip = getenv('REMOTE_ADDR');
}
}
return $ip;
}

This is Output
 
Top