Follow along with the video below to see how to install our site as a web app on your home screen.
Бележка: This feature may not be available in some browsers.
lam3r4370 каза:Можеш да използваш get_browser() , за да вземеш браузъра, вместо getOS и getBrowser методите
<?php
//Инклудваш
include 'GetIPAddress.php';
//Създаваш нов обект
$userInfo = new GetIPAddress();
//Викаш функцията userInfo() която връща масив
$result = $userInfo->userInfo();
//Можеш да достъпваш даден елемент от масива
//В долния пример е града
//echo $result[5];
//Можеш да изведеш и целия масив
foreach ($result as $arr) {
echo $arr . '<br>';
}
?>
Такива грешки се дебъгват с var_dump на въпросната променлива и с проследяване откъде идва.pro12 каза:Пробвах и на платен хост. И излиза грешка PHP Warning: Invalid argument supplied for foreach()
...
Направих както ми каза и излезе това NULLteroristd каза:Премахни за малко foreach-a и дай един var_dump($result);
Това очевидно няма да влезе в ифа, щом $result е null. По-добре да поразръчка въпросния метод userInfo() с echo-та на други променливи.teroristd каза:Пробвай така и кажи дали се получава нещо;
Код:if (is_array($result)) { foreach ($result as $arr) { echo $arr . '<br>'; } }
че трябва да дебъгваш резултата преди json_encode-to, т.е. от file_get_contents():NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit.
public function userInfo() {
$this->_ip = $this->getServerTypes();
$this->_result = json_decode(file_get_contents("http://ip-api.com/" . $this->_ip . "/json"));
if ($this->_result != null) {
$this->_arrResult = array($this->_result->status, $this->_result->country, $this->_result->countryCode,
$this->_result->region, $this->_result->regionName, $this->_result->city, $this->_result->zip,
$this->_result->lat, $this->_result->lon, $this->_result->timezone, $this->_result->isp,
$this->_result->org, $this->_result->as, $this->_result->query);
return $this->_arrResult;
}
}
anonimen каза:Това очевидно няма да влезе в ифа, щом $result е null. По-добре да поразръчка въпросния метод userInfo() с echo-та на други променливи.teroristd каза:Пробвай така и кажи дали се получава нещо;
Код:if (is_array($result)) { foreach ($result as $arr) { echo $arr . '<br>'; } }
Едитнах се ^^pro12 каза:Не става само бяла страница.и така не става.PHP:echo $result[5];