1

How to make function to get visitor ip? I try fixed using related post below Tracking visitor IP/Clicks in PHP How to get client's IP address using javascript only? but cannot fixed yet..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sample Tracking Visitor</title>
<script type="text/javascript">
 function tracking_vistors(cid,url,curl,camp,type) {
    var user_agent = getuseragent();
    var ip = myIP(); // how to make this function track visitor ip 
    var publisher = "2000000001";
    var data = "cid="+cid+"&curl="+curl+"&camp="+camp+"&type="+type+"&url="+url+"&ip="+ip+"&user_agent="+user_agent+"&publisher="+publisher;
    $.ajax({
      type: 'POST',
      url: 'widget/clicktracker.php',
      data: data
    });
 }

</script>
</head>

<body>
</body>
</html>
Community
  • 1
  • 1
apisv2
  • 53
  • 2
  • 9

1 Answers1

1

You can't find the IP from the javascript. You've to send the call to internet or any other service which can return your IP..

I'm adding one service url which will return your IP.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sample Tracking Visitor</title>
<script type="text/javascript" src="http://l2.io/ip.js?var=myip"></script>
<script type="text/javascript">
    function tracking_vistors(cid,url,curl,camp,type) {
       var user_agent = getuseragent();
       var ip = myip; // how to make this function track visitor ip 
       var publisher = "2000000001";
       var data = "cid="+cid+"&curl="+curl+"&camp="+camp+"&type="+type+"&url="+url+"&ip="+ip+"&user_agent="+user_agent+"&publisher="+publisher;
       $.ajax({
                  type: 'POST',
                  url: 'widget/clicktracker.php',
                  data: data
             });
    }

</script>
</head>

<body>
</body>
</html>

This line will send the request to l2.io domain and return the ip in myip variable which I used in the code above.

razahassank
  • 195
  • 8