Working with Session

Working with Session

ASSession Class

By including ASEngine/AS.php file into some of your own files, your session will be automatically started. However, if you want to do it by your self, you need to call startSession() method from ASSession class.


Note! Always start session using this function because it will start secure session!

If you want to destroy existing session, just call destroySession() method:


In order to store something to the session, you can use set method

ASSession::set("something", 5);

And if you want to get something from the session, for example user ID, call get method

$userId = ASSession::get("user_id");

If you want to unset some session item, you can do it by calling destroy method


Session Lifetime

By default, AS session cookie will use lifetime configuration from your php.ini file, which usually means that session cookie will expire right after you close the browser window. In order to modify that, just edit ASSession class and inside startSession function replace $cookieParams["lifetime"] with an integer that represent lifetime of the session cookie in minutes. For example, if you want your cookie to expire after 2 hours, your startSession method should look like following:

public static function startSession()

Session Cookie for Multiple Subdomains

In order to allow auth cookie to be shared across multiple subdomains, just go to ASEngine/ASSession.php, and replace $cookieParams["domain"] with inside startSession method, and you are good to go.