Display visitor source issues
Function getIp (){
$ Onlineip = '';
If (getenv ('http _ CLIENT_IP ') & strcasecmp (getenv ('http _ CLIENT_IP'), 'Unknown ')){
$ Onlineip = getenv ('http _ CLIENT_IP ');
} Elseif (getenv ('http _ X_FORWARDED_FOR ') & strcasecmp (getenv ('http _ X_FORWARDED_FOR'), 'Unknown ')){
$ Onlineip = getenv ('http _ X_FORWARDED_FOR ');
} Elseif (getenv ('remote _ ADDR ') & strcasecmp (getenv ('remote _ ADDR'), 'Unknown ')){
$ Onlineip = getenv ('remote _ ADDR ');
} Elseif (isset ($ _ SERVER ['remote _ ADDR ']) & $ _ SERVER ['remote _ ADDR '] & strcasecmp ($ _ SERVER ['remote _ ADDR'], 'Unknown ')){
$ Onlineip = $ _ SERVER ['remote _ ADDR '];
}
Return $ onlineip;
}
$ Onlineip = getIp ();
$ Ipinfo = json_decode (file_get_contents ("http://ip.taobao.com/service/getIpInfo.php? Ip = ". $ onlineip), true); // decodes the json format of the API and saves it to the ipinfo variable.
?>
IP: |
|
Country: |
|
Province: |
|
City: |
|
County: |
|
Region: |
|
ISP: |
|
I can check the IP address, but only once. In the future, other visitors will check the source of the first visitor.
Using CMS, no data table is created for the visitor source.
The question is the code problem, or the corresponding data table is not created.
Reply to discussion (solution)
Are other visitors using different networks? If two people go out from the same public IP address, the access looks like the same IP address. If your service is on the internet, send it to your friends in other network environments to check whether the same is true.
You can also test this code separately. it has nothing to do with CMS.
Http://ip.taobao.com/service/getIpInfo.php
In this example, no table is required.
Does it mean that all access requests are consent sources? Does the used web server go through a proxy?
Are other visitors using different networks? If two people go out from the same public IP address, the access looks like the same IP address. If your service is on the internet, send it to your friends in other network environments to check whether the same is true.
You can also test this code separately. it has nothing to do with CMS.
Http://ip.taobao.com/service/getIpInfo.php
In this example, no table is required.
Other visitors are not on the same public network and sent to friends from other places for testing. Show my IP
The method for obtaining ip addresses is not rigorous. I didn't expect it to be circulated until now that some people have used it.
The method for obtaining ip addresses is not rigorous. I didn't expect it to be circulated until now that some people have used it.
Please be rigorous
First, you can try $ _ SERVER ['remote _ ADDR.
Or you should find out which variable takes effect in the code and find the problem. And this is also related to the network structure of your own server. You should understand the meaning of the environment Variables in the Predefined Variables section in the PHP manual first. A piece of code should not be directly thrown out. even if someone else solves it for you, this is still a blind spot for you.
I solved the problem because my webpage is static and now it is changed to dynamic. the test is successful.