我是 PHP 新手,正在嘗試使用如下所示的 API 代碼獲取 IP 資訊
$ip = $_SERVER["REMOTE_ADDR"];
$proxycheck_options = array(
'API_KEY' => '######', // Your API Key.
'ASN_DATA' => 1, // Enable ASN data response.
'DAY_RESTRICTOR' => 7, // Restrict checking to proxies seen in the past # of days.
'VPN_DETECTION' => 1, // Check for both VPN's and Proxies instead of just Proxies.
'RISK_DATA' => 1, // 0 = Off, 1 = Risk Score (0-100), 2 = Risk Score & Attack History.
'INF_ENGINE' => 1, // Enable or disable the real-time inference engine.
'TLS_SECURITY' => 0, // Enable or disable transport security (TLS).
'QUERY_TAGGING' => 1, // Enable or disable query tagging.
'CUSTOM_TAG' => '', // Specify a custom query tag instead of the default (Domain Page).
'BLOCKED_COUNTRIES' => array('Wakanda', 'CN'), // Specify an array of countries or isocodes to be blocked.
'ALLOWED_COUNTRIES' => array('Azeroth', 'US') // Specify an array of countries or isocodes to be allowed.
);
$result_array = \proxycheck\proxycheck::check($ip, $proxycheck_options);
echo "<pre>";
print_r($result_array);
echo "</pre>";
echo $result_array[0]->status;
print_r 給了我這樣的回應
Array
(
[status] => ok
[node] => LETO
[157.32.X.X] => Array
(
[asn] => AS55836
[provider] => Reliance Jio Infocomm Limited
[continent] => Asia
[country] => India
[isocode] => IN
[region] => Gujarat
[regioncode] => GJ
[city] => Ahmedabad
[latitude] => 23.0276
[longitude] => 72.5871
[proxy] => no
[type] => Business
[risk] => 0
)
[block] => no
[block_reason] => na
)
我有興趣從中獲取狀態、提供者和代理值,但它給了我這樣的錯誤
PHP Notice: Trying to get property 'status' of non-object in
這里的任何人都可以幫助我如何正確地從這種型別的陣列中獲取值?
謝謝!
uj5u.com熱心網友回復:
根據您向我們展示的資訊,$result_array沒有0索引(更不用說包含具有屬性的物件的索引了)。
該print_r結果告訴我們,這是一個關聯陣列,因此,你可以簡單地直接進入了“狀態”屬性為排列的指標:
echo $result_array["status"];
PHP 手冊頁中有關陣列的更多資訊和示例以及許多其他在線位置。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/369995.html
