1
I’m relatively new with PHP and I started going through a site. And I found the following code that was going wrong:
<?php
function ip_details() {
$json = file_get_contents("http://ipinfo.io/");
$details = json_decode($json);
return $details;
}
$details = ip_details();
$ip = $details->ip;//34
$local = $details->city; //35
?>
This is the mistake that comes to me:
PHP error was encountered Severilty: Notice Message: trying to get Property of non-object Filename: views/login_view.php Line Number: 34
I know something about PHP but I didn’t understand what was here and I’ve been searching but I couldn’t find anything to make me understand what that code was.
Does anyone understand this code that can explain to me?
I removed the "Good" from your question, avoid using it.
– Erlon Charles
I did the test here and ran smoothly, see if the server you are running on has file_get_contents support for external addresses;
– Adir Kuhn
You can also var_dump($Details); to see what content is in the variable
– Adir Kuhn
Tried to put it like this:
$json = file_get_contents("http://ipinfo.io/json");
?– Franchesco
Instead of posting questions like "what this does", try to focus on the problem. In this case the problem would be with the data brought by
file_get_contents
that were not decoded byjson_decode
. And do not use images to illustrate an error that is a text message "Trying to get Property of non-object"– Guilherme Nascimento
Another thing, it seems to me that the software is using MVC, I disagree to do executions and treatments in the View layer. I recommend studying MVC first and using PHP documentation.
– Guilherme Nascimento