Answer the question
In order to leave comments, you need to log in
Why does it always return the last variable?
always returns the last id
<?php
class Login
{
protected $id;
public function Login()
{
$msg = '';
$firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);
$json = $firebase->get(DEFAULT_PATH . "/ARCusers/");
$json_ary = json_decode($json, true);
if (is_array($json_ary) || is_object($json_ary)) {
foreach ($json_ary as $this->id => $val) {
$getEmail = $firebase->get(DEFAULT_PATH . "/ARCusers/$this->id/email");
$getPassword = $firebase->get(DEFAULT_PATH . "/ARCusers/$this->id/password");
$activation = $firebase->get(DEFAULT_PATH . "ARCusers/$this->id/activation");
if (isset($_POST['login']) && !empty($_POST['email'])
&& !empty($_POST['password'])
) {
if ('"' . $_POST['email'] . '"' == $getEmail &&
'"' . $_POST['password'] . '"' == $getPassword
) {
$_SESSION['valid'] = true;
$_SESSION['timeout'] = time();
$_SESSION['email'] = '"' . $_POST['email'] . '"';
if ($activation == 'true') {
echo "Logged in.";
header("Location: newwelcome.php");
// echo "$this->id";
return $this->id;
} else {
echo "verify your email";
}
} else {
$msg = 'Wrong email or password';
}
}
}
}
}
}
?>
<?php
include_once "new login.php";
class OpenPage extends Login
{
private $getId;
public function openpage()
{
$this->Login();
$this->getId = $this->id;
$firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);
echo $this->id;;
}
}
$openpage = new OpenPage();
?>
Answer the question
In order to leave comments, you need to log in
Are you iterating over the array changing $this->id
in foreach ($json_ary as $this->id => $val) {
why did you decide that you would get something other than the last key?
the login function returns the first $this->id that satisfies the conditions, but the Login class itself will always contain the last value in $this->id.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question