Home >Backend Development >PHP Problem >PHP implements city switching or jump based on IP address

PHP implements city switching or jump based on IP address

coldplay.xixi
coldplay.xixiOriginal
2021-02-23 17:36:322618browse

PHP method to implement city switching or jump based on IP address: 1. Jump to the specified page js to obtain the city based on the IP address, the code is [var city='']; 2. Based on the IP address All cities jump to the specified page.

PHP implements city switching or jump based on IP address

The operating environment of this tutorial: Windows 7 system, PHP version 5.6, DELL G3 computer. This method is suitable for all brands of computers.

How to use PHP to switch or jump cities based on IP address:

At this point, the problem is actually very simple, and it can be solved with simple js. Section C is as follows:

//Jump to the specified page based on the IP address to obtain the city using js

var city=&#39;<?echo ipCity($xp_UserIp);?>&#39;;

//Jump to the specified page based on the IP address for all cities

if(city.indexOf("上海市")>=0){
  window.location.href="http://shanghai.demo.com/";
}

Place the beginning A segment code and the above C segment code at the beginning and end of the B segment code respectively, and then we add the following code to the page that needs to be jumped:

<script src="/ipcity/ipaddress.php" type="text/javascript" language="javascript"></script>

Related Video recommendation: PHP programming from entry to proficiency

The above is the detailed content of PHP implements city switching or jump based on IP address. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn