Include not working

Website URL

http://driver-db.rf.gd/

Error Message

Fatal error : Uncaught Error: Class “User” not found in /home/vol10_1/infinityfree.com/if0_36244413/htdocs/php/login-register-API.php:87 Stack trace: #0 {main} thrown in /home/vol10_1/infinityfree.com/if0_36244413/htdocs/php/login-register-API.php on line 87

Other Information

My code

<?php
    // Enable error reporting
    error_reporting(E_ALL);

    // Display errors on screen
    ini_set('display_errors', 1);

    include_once('classes/User.php');
    include_once('classes/UserEmployee.php');

    // Define TokenGenerator class
    class TokenGenerator {
        public static function generateToken($length = 32) {
            // Generate a random string of specified length
            $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            $token = '';
            for ($i = 0; $i < $length; $i++) {
                $token .= $characters[rand(0, strlen($characters) - 1)];
            }
            return $token;
        }
    }

    // Define authentication function
    function autentication($user) {
        $status = false;

        if(isset($_COOKIE['id']) && isset($_COOKIE['email']) && isset($_COOKIE['token'])) {
            $id = $_COOKIE['id'];
            $email = $_COOKIE['email'];
            $token = $_COOKIE['token'];

            $user->id = $id;
            $user->find(TRUE, FALSE);
                
            if ($user->email == $email && $user->token == $token) {
                $status = true;
            }
        }

        if(!$status) {
            setcookie('id', "", time() - 3600, "/"); 
            setcookie('email', "", time() - 3600, "/"); 
            setcookie('token', "", time() - 3600, "/"); 
            die();
        }
    }

    // Define action variable
    $action = isset($_POST['action']) ? $_POST['action'] : null;

    // Initialize return object
    $returnObj = new stdClass();
    $returnObj->status = false;
    $returnObj->message = "Something is wrong..";

    // Handle signup action
    if ($action == "signup") {
        $email = $_POST['username'];
        $name = $_POST['name'];
        $surname = $_POST['surname'];
        $password = $_POST['password'];
        $number = $_POST['number'];

        if(isset($name) && $name!='' && isset($surname) && $surname!='' && isset($email) && $email!='' && isset($password) && $password!='' && isset($number) && $number!=''){
            $user = new User();

            $user->name = $name;
            $user->surname = $surname;
            $user->email = $email;
            $user->password = $password;
            $user->number = $number;

            if($user->save()){
                $returnObj->status=true;
                $returnObj->message="User Save Successfully!";
            }
        }
    }

    // Handle login action
    if ($action == "login") {
        $email = $_POST['username'];
        $password = $_POST['password'];

        if(isset($email) && $email!='' && isset($password) && $password!=''){
            $user = new User();
            $user->email = $email;

            if($user->find(FALSE,TRUE)){
                if($user->password == $password){
                    $token = TokenGenerator::generateToken(32);
                    $user->token = $token;
                    
                    if($user->update()){
                        setcookie('email', $user->email, $expirationTime, '/');
                        setcookie('token', $user->token, $expirationTime, '/');
                        setcookie('id', $user->id, $expirationTime, '/');

                        $returnObj->status=true;
                        $returnObj->message="User Logged Successfully!";
                    }
                }
            }
        }
    }

    // Handle signupuser action
    if ($action == "signupuser") {
        $email = $_POST['username'];
        $name = $_POST['name'];
        $surname = $_POST['surname'];
        $password = $_POST['password'];
        $number = $_POST['number'];
        $id = isset($_COOKIE['id']) ? $_COOKIE['id'] : null;

        if(isset($name) && $name!='' && isset($surname) && $surname!='' && isset($email) && $email!='' && isset($password) && $password!='' && isset($number) && $number!='' && isset($id)){
            $user = new UserEmployee();

            $user->name = $name;
            $user->surname = $surname;
            $user->email = $email;
            $user->password = $password;
            $user->number = $number;
            $user->userId = $id;

            if($user->save()){
                $returnObj->status=true;
                $returnObj->message="User Save Successfully!";
            }
        }
    }

    // Check for authentication
    if(isset($_COOKIE['id']) && isset($_COOKIE['email']) && isset($_COOKIE['token'])){
        $user = new User();
        autentication($user);
    }

    // Output JSON response
    echo json_encode($returnObj);
?>

I only see this

image

If you need help, write clearly as to how you managed to reproduce this error

5 Likes

try login with this credentials
user : foobar password : 1234

problem solved it was the ftp server problem

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.