Skip to content
Advertisement

Keeping variables in a class after refresh PHP

i come here with a question: I have a class User created in a php file, this class is included in 2 main files, it’s there any chance to save values in that file? I mean, in the moment when i refresh the page, my variables saved in class are gone, and i want to save them without using $_SESSION. So, i’m so interested to know if there’s a solution, or i just need to use the statement $_SESSION to refresh my variables everytime?

public function getVariables($email){
        $stmt = $this->DB->Connection->prepare("SELECT * FROM $this->type WHERE email=:email",array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
        $stmt->bindValue(':email', $email, PDO::PARAM_STR);
        $stmt->execute();
        $result = $stmt->fetch();
        $this->id = $result[0];
        $this->fname = $result[1];
        $this->lname = $result[2];
        $this->name = $this->lname." ".$this->fname;
        $this->CNP = $result[3];
        $this->birthday = $result[4];
        $this->email = $result[5];
        $this->university = $result[6];
        $this->faculty = $result[7];
        $this->password = $result[8];
        $this->gender = $result[9];
        $this->imgURL = $result[10];
        $this->darkmode = $result[12];
        $this->reset_code = $result[13];
        $this->reset_active = $result[14];
        $this->activationCode = $result[15];
        $this->activeDate = $result[16];
        $this->loginIP = $result[17];
        $this->loginIPS = $result[18];
        $this->auth = $result[19];
        $this->activated = $result[20];
    }

Advertisement

Answer

PHP is a stateless language. So unless you store the data in session, DB, file, or any other external resource, it’s not achieveable to keep the values after reload.

So, i’m so interested to know if there’s a solution, or i just need to use the statement $_SESSION to refresh my variables everytime?

You’ll need to use $_SESSION or another external resource.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement