@Kar92

Почему не передается id в другой класс?

<?php

class Login
{
    protected $id;


    function Login()
    {

        require 'init.php';
        session_start();
        if (!isset($_SESSION['email'])) {

            $email = isset($_POST['email']) ? $_POST['email'] : '';
            $password = isset($_POST['password']) ? $_POST['password'] : '';

            $password = htmlspecialchars($password);

            $email = '"' . $email . '"';
            $password = '"' . $password . '"';
            $error = false;


            if (isset($_POST['submit'])) {

                if (!empty($email) && !empty($password)) {

                    $firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);
                    $json = $firebase->get(DEFAULT_PATH . "/ARCusers/");


                    $json_ary = json_decode($json, true);
                    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 ($email == $getEmail && $password == $getPassword) {
                            $error = false;

                        } else {
                            $error = true;
                        }

                        if ($error) {
                            echo "Error in email or/and password.";
                        }

                        if (!$error) {
                            //login

                            if ($activation == 'true') {
                                $_SESSION['email'] = $email;
                                echo "Logged in.";
                                header("Location: LicenseKey.php?);
                            } else {
                                echo "verify your email";
                            }
                        }
                    }
                } else {
                    echo "Fill in all the details.";
                }
            }
        }

    }

}

$Login = new Login();
?>


<b><?php
    if (isset($_SESSION['email'])) {
//        echo 'You are already logged in.';
    } else {
    echo 'Log in:';
    ?></b>
<br>
<br>

    <form action="login.php" method="post">

        Email address:
        <br>
        <input type="text" name="email" maxlength="128">
        <br>
        <br>

        Password:
        <br>
        <input type="password" name="password" maxlength="128">
        <br>
        <br>

        <input type="submit" name="submit" value="Submit">

    </form>

<?php } ?>


<?php


include "Login.php";

class LicenseKey extends Login
{
    private $getId;

    function LicenseKey()
    {
        $this->getId = $this->id;
        $firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);
        $license_key = $firebase->get(DEFAULT_PATH . "/ARCusers/$this->getId/License/license key");
        if (isset($_GET['LicenseKey'])) {

            if ($license_key == '"' . $_GET['addlicensekey'] . '"') {

                $firebase->set(DEFAULT_PATH . "/ARCusers/$this->getId/License/license key activation", true);

            } else {
                echo "false";
                echo $this->getId;


            }
        }
    }
}
$licensekey = new LicenseKey();

?>


<!DOCTYPE HTML>
<html>
<head>
    <title>Firebase</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link href="css/style.css" rel="stylesheet">
</head>
<body>


<form class="pure-form" method="get">

    <h2>License key</h2>

    <input name="addlicensekey" placeholder="put your license key" type="text">
    <br><br><br>

    <button type="submit" onclick="" name="LicenseKey" class="pure-button pure-button-primary">
        Submit
    </button>
    <br>
    <hr>
    <br>

</form>


</body>
</html>
  • Вопрос задан
  • 157 просмотров
Пригласить эксперта
Ответы на вопрос 1
@metnee
Он должен передаваться. Вероятно что $id просто пустой.
Попробуйте задать какое-то значение ему и проверить так ли это, например:
class Login
{
    protected $id = 123;
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
YCLIENTS Москва
от 200 000 до 350 000 ₽
Ведисофт Екатеринбург
от 25 000 ₽
ИТЦ Аусферр Магнитогорск
от 100 000 до 160 000 ₽
27 апр. 2024, в 17:31
150000 руб./за проект
27 апр. 2024, в 16:39
1000 руб./в час
27 апр. 2024, в 16:38
30000 руб./за проект