Reputation: 37
I'm trying what should be a pretty easy loginn form to a localhost database, but when I push log in it doesn't do anything. Basically I just get as input a username and password and try to get the data (I know the url looks weird as uid=password but it is as it has to be).
Then I compare what the database should return (name and uid) and compare those fields. Any hint would be of great help!
<?php
$log = file_get_contents("http://localhost:8080/users?uid=$password");
$data = json_decode($log);
$username= $_POST['username'];
$password=$_POST['password'];
if($log.empty) {
header("Location: inici.html");
exit;
}
if(($username == $data->Nombre) && ($password == $data->UID)){
header("Location: inici.html");
exit;
}
else
{
header("Location: login.html");
exit;
}
?>
Upvotes: 0
Views: 34
Reputation: 76789
At first you write:
$data = json_decode($log);
and then you produce a run-time error with illegal/meaningless syntax:
if($log.empty) {
$log
is a string, while you might have meant the $data
array
or object
. In PHP there is only an ->
object-access operator ... the .
operator just concatenates.
You could check for: if(! empty($log))
to determine an empty response.
Upvotes: 2