获取本机外网ip地址的老问题
遇到了跟之前的一篇帖子一样的问题
各种方法获取本地外网ip时,各种返回::1。
大部分是说因为ipv6的原因。但关掉后,电脑彻底无法上网了。
不知道现在有没有除了接口以外的解决办法。
回复讨论(解决方案)
ipv6 的 ::1,就是 ipv4 的 127.0.0.1
不知道你是怎么做的
你获取的是ipv6?
ipv6 的 ::1,就是 ipv4 的 127.0.0.1
不知道你是怎么做的
度娘“本机外网ip地址 php”就会出现n中解决办法,下面截取一例:
function get_onlineip() { $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; } var_dump(get_onlineip());
本机是武汉的,本意是想获得本机IP: 27.19.xxx.xxx 湖北省武汉市 电信 这种ip地址。$_SERVER我也不是很懂。在localhost上运行的,所以出现::1是因为ipv6,还是localhost,我也不是很清楚。可以不深究这个问题,因为只想从php里获得 27.19.xxx.xxx这种ip地址
麻烦了
你在本机访问就只能得到 ::1 或 127.0.0.1 或 你机器的 ip
外网的 ip 要从外网访问才能得到
如果是Linux系统用php执行“curl ifconfig.me”可以得到外网IP
你在本机访问就只能得到 ::1 或 127.0.0.1 或 你机器的 ip
外网的 ip 要从外网访问才能得到
嗯,这个别人也跟我讲过。
我奇怪的是,度娘“本机外网ip地址”,就会给我27.19.xxx.xxx的ip地址。我也没有一个页面可以给他访问来获取我外网的ip地址啊,所以也不能在cmd中用ipconfig。
那度娘是怎么得到“27.19.xxx.xxx”的?
如果是Linux系统用php执行“curl ifconfig.me”可以得到外网IP
谢啦~~目前用的wamp环境。
你访问他时,用的不就是外网 ip 吗?
你访问他时,用的不就是外网 ip 吗?
懂了。。3Q。。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
