WebFioriAPI ReferenceLearnDownloadContributeLearn{{result.parent_page}} > {{result.title}}{{result.title}}Classes{{result.class_name}}{{result.summary}}Methods{{result.name}}{{result.summary}}

namespace \webfiori\framework\session

class Session

Class Attributes Summary

const DEFAULT_SESSION_DURATIONThe default lifetime for any new session (in minutes).const STATUS_EXPIEREDA constant that indicates the session was expired.const STATUS_INACTIVEA constant that indicates the session was initialized but not started or resumed.const STATUS_KILLEDA constant that indicates the session has been killed by calling the method 'Session::kill()'.const STATUS_NEWA constant that indicates the session was just created.const STATUS_PAUSEDA constant that indicates the session was paused.const STATUS_RESUMEDA constant that indicates the session has been resumed.

Class Methods Summary

public function __construct(array$options)Creates new instance of the class.public function __toString()Returns a JSON string that represents the session.public function close()Store session state and pause the session.public function get(string$varName)Returns the value of a session variable.public function getCookieHeader()Returns a string which can be passed to the function 'header()' to set session cookie.public function getCookieParams()Returns an associative array that contains session cookie's information.public function getDuration()Returns the amount of time at which the session will be kept alive in.public function getId()Returns the ID of the session.public function getIp()Returns the IP address of the client at which the request has come from.public function getLangCode(boolean$forceUpdate)Returns session language code.public function getName()Returns the name of the session.public function getPassedTime()Returns the number of seconds that has been passed since the session started.public function getRemainingTime()Returns number of seconds remaining before the session timeout.public function getResumedAt()Returns the time at which the session was resumed at in seconds.public function getStartedAt()Returns the time at at which the session was started at.public function getStatus()Returns the status of the session.public function getUser()Returns an object of type 'User' that represents session user.public function getVars()Returns an associative array that contains all session variables.public function has(string$varName)Checks if the session has a given value or not.public function isPersistent()Checks if the session cookie is persistent or not.public function isRefresh()Checks if session timeout time will be refreshed with every request or not.public function isRunning()Checks if the session is started and running or not.public function kill()public function pull(string$varName)Retrieves the value of a session variable and removes it from the session.public function reGenerateID()Re-create session ID.public function remove(string$varName)Removes the value of a session variable.public function serialize()Serialize the session.public function set(string$name, mixed$val)Sets session variable.public function setDuration(int$time)Sets session duration.public function setIsRefresh(boolean$bool)Sets if the session timeout will be refreshed with every request or not.public function setSameSite(string$val)Sets the value of the property 'SameSite' of session cookie.public function setUser(User$userObj)Sets the user that represents session user.public function start()Resumes or starts new session.public function toJSON()Returns an object of type 'Json' that represents the session.public function unserialize(string$serialized)Unserialize a session and restore its data in the instance at which the method is called on.

Class Attributes Details

const DEFAULT_SESSION_DURATIONThe default lifetime for any new session (in minutes). const STATUS_EXPIEREDA constant that indicates the session was expired. const STATUS_INACTIVEA constant that indicates the session was initialized but not started or resumed. const STATUS_KILLEDA constant that indicates the session has been killed by calling the method 'Session::kill()'. const STATUS_NEWA constant that indicates the session was just created. const STATUS_PAUSEDA constant that indicates the session was paused. const STATUS_RESUMEDA constant that indicates the session has been resumed.

Class Methods Details

public function __construct(array$options)Creates new instance of the class.

Parameters:

  • array $options An array that contains session options. Available options are:
    • name: The name of the session. A valid name can only consist of [a-z], [A-Z], [0-9], dash and underscore. This must be provided or the method will throw an exception.
    • duration: The duration of the session in minutes. Must be a number greater than or equal to 0. If 0 is given, it means the session is not persistent. If the duration is invalid, it will be set to Session::DEFAULT_SESSION_DURATION
    • refresh: A boolean which is set to true if session timeout time will be refreshed with every request. Default is false.
public function __toString()Returns a JSON string that represents the session. Returns: string public function close()Store session state and pause the session. Note that session state will be stored only if it is running.public function get(string$varName)Returns the value of a session variable.

Parameters:

  • string $varName The name of the variable.
Returns: null|mixedIf a variable which has the given name is found, its value is returned. If no such variable exist, the method will return null.
public function getCookieHeader()Returns a string which can be passed to the function 'header()' to set session cookie. Returns: stringThe string that will be returned will have the following format: '<cookie-name>=<val>; expires=<time>; path=/ SameSite=<Lax|None|Strict>'public function getCookieParams()Returns an associative array that contains session cookie's information. Returns: arrayThe array will contain the following indices:
  • expires: The time at which session cookie will expire. If the cookie is persistent, this will have a non-zero value.
  • domain: The domain at which session cookie will operate in.
  • path: The path that the cookie will operate in.
  • httponly
  • secure
  • samesite
public function getDuration()Returns the amount of time at which the session will be kept alive in. Returns: intThis method will return session duration in seconds. The default duration of any new session is 120 minutes (7200 seconds).public function getId()Returns the ID of the session. Returns: stringThe ID of the session.public function getIp()Returns the IP address of the client at which the request has come from. Returns: string public function getLangCode(boolean$forceUpdate)Returns session language code.

Parameters:

  • boolean $forceUpdate Set to true if the language is set and want to reset it. The reset process depends on the attribute 'lang'. It can be send via 'get' request, 'post' request or a cookie. If no language code is provided and the parameter '$forceUpdate' is set to true, 'EN' will be used. If the given language code is not in the given array and the parameter '$forceUpdate' is set to true, 'EN' will be used.
Returns: string|nulltwo digit language code (such as 'EN'). If the session is not running or the language is not set, the method will return null.
public function getName()Returns the name of the session. Returns: stringThe name of the session as string.public function getPassedTime()Returns the number of seconds that has been passed since the session started. Returns: intThe number of seconds that has been passed since the session started. If the session status is Session::STATUS_INACTIVE, the method will return 0.public function getRemainingTime()Returns number of seconds remaining before the session timeout. Returns: intIf the session is persistent or set to refresh for every request, the method will return 0. Other than that, it will return remaining time. If the session has no remaining time, it will return -1.public function getResumedAt()Returns the time at which the session was resumed at in seconds. Returns: intThe time at which the session was resumed at in seconds. If the session is not running, the time will be 0. If the session is new, the time will be the same as start time.public function getStartedAt()Returns the time at at which the session was started at. Returns: intThe method will return the time in seconds. If the session is not running, the method will return 0.public function getStatus()Returns the status of the session. Returns: stringThe status of the session.public function getUser()Returns an object of type 'User' that represents session user. Returns: UserAn object of type 'User' that represents session user.public function getVars()Returns an associative array that contains all session variables. Returns: arrayAn associative array that contains all session variables. The indices will be variables names and the value of each index is the variable value.public function has(string$varName)Checks if the session has a given value or not. Note that the method will always return false if the session is not running.

Parameters:

  • string $varName The name of the variable that has the value.
Returns: booleanIf the value exist, the method will return true. Other than that, the method will return false.
public function isPersistent()Checks if the session cookie is persistent or not. A session is persistent if its duration is greater than 0 minutes (has a duration).Returns: booleanIf the session cookie is persistent, the method will return true. false otherwise.public function isRefresh()Checks if session timeout time will be refreshed with every request or not. This method must be called only after calling the method 'SessionManager::initSession()'. or it will throw an exception.Returns: booleantrue If session timeout time will be refreshed with every request. false if not.public function isRunning()Checks if the session is started and running or not. Returns: Ifthe status of the session is Session::STATUS_NEW or Session::STATUS_RESUMED, the method will return true. Other than that, the method will return false.public function kill()public function pull(string$varName)Retrieves the value of a session variable and removes it from the session.

Parameters:

  • string $varName The name of the variable.
Returns: mixed|nullIf the variable exist and its value is set, the method will return its value. If the value is not set or the session is not running, the method will return null.
public function reGenerateID()Re-create session ID. Returns: stringThe new ID of the session.public function remove(string$varName)Removes the value of a session variable.

Parameters:

  • string $varName The name of the variable.
Returns: booleanIf the value was deleted, the method will return true. If the variable does not exist or the variable does not exist, the method will return false.
public function serialize()Serialize the session. Returns: stringThe method will return a string that represents serialized session data.public function set(string$name, mixed$val)Sets session variable. Note that session variable will be set only if the session is running.

Parameters:

  • string $name The name of the variable. Must be non-empty string.
  • mixed $val The value of the variable. It can be any thing.
Returns: booleanIf the variable is set, the method will return true. If not, the method will return false.
public function setDuration(int$time)Sets session duration. Note that this method will also updates the 'expires' attribute of session cookie. Also, note that if the new duration less than the passed time, the session will expire.

Parameters:

  • int $time Session duration in minutes.
Returns: booleanIf session duration is updated, the method will return true. False otherwise.
public function setIsRefresh(boolean$bool)Sets if the session timeout will be refreshed with every request or not.

Parameters:

  • boolean $bool If set to true, timeout time will be refreshed. Note that the property will be updated only if the session is running.
public function setSameSite(string$val)Sets the value of the property 'SameSite' of session cookie.

Parameters:

  • string $val It can be one of the following values, 'Lax', 'Strict' or 'None'. If any other value is provided, it will be ignored.
public function setUser(User$userObj)Sets the user that represents session user. Note that the user will be set only if the session is active.

Parameters:

  • User $userObj An object of type 'User'.
public function start()Resumes or starts new session. This method works as follows, it tries to read a session from sessions storage using the ID of the session. If a session is found, it will populate the instance with session values taken from the storage. If no session was found, the method will initialize new one.public function toJSON()Returns an object of type 'Json' that represents the session. Returns: Json public function unserialize(string$serialized)Unserialize a session and restore its data in the instance at which the method is called on.

Parameters:

  • string $serialized The serialized session as string.
Returns: booleanIf the Unserialize was successfully completed, the method will return true. If Unserialize fails, the method will return false.
mdi-menuAll Classesmdi-chevron-leftAnchorBrCodeSnippetHTMLDocHTMLListHTMLNodeHTMLTableHeadNodeInputJsCodeLabelListItemOrderedListParagraphRadioGroupTableCellTableRowUnorderedListInvalidNodeNameExceptionTemplateNotFoundExceptionCaseConverterJsonJsonConverterJsonIJsonTypesPropertyAPIFilterAbstractWebServiceManagerInfoServiceParamTypesRequestRequestParameterResponseUriWebServicesManagerAccessAutoLoaderConfigConfigControllerDBEAbstractWebServiceExtendedWebServicesManagerFileLoggerPrivilegePrivilegesGroupThemeThemeLoaderUploadFileUploaderUserUtilWebFioriAppLanguageErrorBoxHTTPCodeViewMessageBoxServerErrViewStarterPageWebPageDatabaseSessionStorageDefaultSessionStorageMSSQLSessionDataTableMSSQLSessionsTableMySQLSessionDataTableMySQLSessionsTableSessionSessionOperationsSessionStorageSessionsManagerRouterRouterUriAbstractMiddlewareMiddlewareManagerEmailMessageSMTPAccountSMTPServerClassLoaderExceptionFileExceptionInitializationExceptionInvalidCRONExprExceptionMissingLangExceptionNoSuchThemeExceptionRoutingExceptionSMTPExceptionSessionExceptionUIExceptionAbstractJobCronCronEmailCronJobJobArgumentCronLoginViewCronTasksViewCronViewCronLoginServiceCronLogoutServiceCronServicesManagerForceCronExecutionServiceGetJobsServiceCLICLICommandInputStreamOutputStreamStdInStdOutClassWriterLangClassWriterQueryClassWriterServiceHolderThemeClassWriterWebServiceWriterCreateCLIClassHelperCreateCronJobCreateMiddlewareCreateTableCreateTableObjCreateThemeHelperCreateWebServiceAddCommandCreateCommandCronCommandHelpCommandListCronCommandListRoutesCommandListThemesCommandRunSQLQueryCommandSettingsCommandTestRouteCommandUpdateSettingsCommandUpdateTableCommandVersionCommandAbstractQueryColumnColumnFactoryConditionConnectionConnectionInfoDatabaseDatabaseExceptionDateTimeValidatorEntityMapperExpressionForeignKeyJoinTableResultSetSelectExpressionTableWhereExpressionMySQLColumnMySQLConnectionMySQLQueryMySQLTableMSSQLColumnMSSQLConnectionMSSQLQueryMSSQLTableAbstractCollectionComparableLinkedListNodeQueueStack
Powered By: WebFiori Framework, Vue and VuetifyAll Rights Reserved © 2018 - 2024