PHP session using class

Asked

Viewed 507 times

2

Hello, I’m new to PHP and would like to know if you can create a class to manage the user session.

It would be a function to log in and another to destroy the session.

If there’s a way to create, how could I be doing it ?

  • 4

    How about using without a class? What gains you expect to have by creating a class?

  • 1

    @mustache of almost every inconsistency of PHP, putting OOP is increasingly looking to me as one of the worst. Now no one else wants to learn real PHP.

1 answer

4


If I understand correctly, you want a class that has the function of starting and destroying a session, so there’s a brief example

class Session {
    public static function init() {
        if(session_id() == '') {
            session_start();
        }
    }

    public static function destroy() {
        session_destroy();
    }
}
  • Thank you @lai0n was just what I was wondering, if there was a way to create a class to manage this, because creating separate files didn’t seem like the best option.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.