In a ThinkPHP project, a server-side request to https://my.ipin.io/info checks the outbound IP used by the server when it accesses the public internet. This is for operations diagnostics, proxy checks, and cloud server region verification, not visitor personalization.
API explanation
A server-side call checks the server outbound IP and returns the IP, country, region, and city exposed by the server on the public network.
{"ip":"185.220.236.7","country":"TW","region":"Taiwan","city":"Taipei"}
Use cases
These scenarios show the value of the IP information interface while clearly separating server IP from visitor IP.
- These scenarios show the value of the IP information interface while clearly separating server IP from visitor IP.
- How to Check Server Outbound IP in ThinkPHP
- API explanation
- SEO and UX recommendations
Implementation logic
Before implementation, identify the requester: server requests return server IP, while browser requests return visitor IP.
- Before implementation, identify the requester: server requests return server IP, while browser requests return visitor IP.
- A server-side call checks the server outbound IP and returns the IP, country, region, and city exposed by the server on the public network.
- All examples below use
https://my.ipin.io/infodirectly, with localized comments and interface text. - Default content should remain complete and readable, while regional content acts as an enhancement. Search engines can crawl stable content, and the page remains usable if the API fails.
Code example
All examples below use https://my.ipin.io/info directly, with localized comments and interface text.
ThinkPHP Controller
<?php
namespace app\controller;
use app\BaseController;
class IpController extends BaseController
{
public function server()
{
$default = [
'ip' => 'Unknown',
'country' => 'Unknown',
'region' => 'Unknown',
'city' => 'Unknown',
];
try {
// Server-side call to /info: checks the server outbound IP.
$json = @file_get_contents('https://my.ipin.io/info');
$data = json_decode($json, true);
$info = is_array($data) ? array_merge($default, $data) : $default;
} catch (\Throwable $e) {
$info = $default;
}
return view('server_ip', ['info' => $info]);
}
}
server_ip.html
<div class="ip-card">
<h2>Server outbound IP information</h2>
<p>IP:{$info.ip|default='Unknown'}</p>
<p>Country:{$info.country|default='Unknown'}</p>
<p>Region:{$info.region|default='Unknown'}</p>
<p>City:{$info.city|default='Unknown'}</p>
</div>
SEO and UX recommendations
Default content should remain complete and readable, while regional content acts as an enhancement. Search engines can crawl stable content, and the page remains usable if the API fails.
Common mistakes
The following issues affect article accuracy, code usability, and the credibility of the API explanation.
- The following issues affect article accuracy, code usability, and the credibility of the API explanation.
- Default content should remain complete and readable, while regional content acts as an enhancement. Search engines can crawl stable content, and the page remains usable if the API fails.
- Before implementation, identify the requester: server requests return server IP, while browser requests return visitor IP.
- These scenarios show the value of the IP information interface while clearly separating server IP from visitor IP.
Summary
A server-side call checks the server outbound IP and returns the IP, country, region, and city exposed by the server on the public network.
FAQ
The questions below are written specifically for this article and are directly related to the implementation.