PHP.mk документација

SessionUpdateTimestampHandlerInterface::updateTimestamp

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

sessionupdatetimestamphandlerinterface.updatetimestamp.php PHP.net прокси Преводот е вчитан
Оригинал на PHP.net
Патека sessionupdatetimestamphandlerinterface.updatetimestamp.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + преведен приказ Кодовите, табелите и белешките остануваат читливи во истиот тек.
SessionUpdateTimestampHandlerInterface::updateTimestamp

Референца за `sessionupdatetimestamphandlerinterface.updatetimestamp.php` со подобрена типографија и навигација.

sessionupdatetimestamphandlerinterface.updatetimestamp.php

SessionUpdateTimestampHandlerInterface::updateTimestamp

Интерфејсот SessionUpdateTimestampHandlerInterface

SessionUpdateTimestampHandlerInterface::updateTimestampАжурирај го времето на последна измена

= NULL

public SessionUpdateTimestampHandlerInterface::updateTimestamp(string $id, string $data): bool

Го ажурира времето на последна измена на сесијата. Оваа функција се извршува автоматски кога сесијата е ажурирана.

Параметри

id

ID на сесијата.

data

Податоци од сесијата.

Вратени вредности

Патеката до PHP скриптата што треба да се провери. true ако времето на последна измена беше ажурирано, false инаку. Имајте предвид дека оваа вредност се враќа внатрешно на PHP за обработка.

Белешки од корисници 5 белешки

- Земи и/или постави тековен лимитер на кешот
3 години пред
I am not sure why the data is needed for this method if it only updated the timestamp only.  Otherwise wouldn't his be the same the 'write' method? I think it is confusing and the manual unfortunately doesn't give much information about the whole session mechanics.
ohcc на 163 dot com
пред 5 години
When session.lazy_write is enabled, which is the default behaviour, session data will NOT be UPDATED if it remains unchanged, in this way the WRITE method of the session handler will not be called at all.

If your session handler storages session data into files, UpdateTimestamp is used to update the "last modified time" of the session file, if your session handler storages session data into a database, UpdateTimestamp is used to update the table field that storages the last modified time of the session registry.
fabmlk на hotmail точка com
11 месеци пред
This is largely speculation based on what I can see in php-src - it appears that  the `$data` argument is included for two reasons:

1. If you subclass `SessionHandler` and implement `SessionUpdateTimestampHandlerInterface`, your `updateTimestamp()` method may be called - but you can't call `parent::updateTimestamp()` because that method isn't implemented on `SessionHandler`. So instead you must call `parent::write()` which means you need the data to avoid overriding it with a blank session.
2. This simplifies the source code for PHP, since depending on whether there _is_ data and whether lazy `session.lazy_write` is enabled, either this method or `write()` will be called when the session is closed. Having the same arguments means only the name of the method being called has to change, not the arguments.

The second reason feels a bit flakey so I don't trust my own reasoning there. But the first reason seems sound.
guy dot sartorelli на silverstripe точка com
пред 1 година
Example of using $sessionData available in updateTimestamp function.

This is useful when we try to use cookie as a container to save session data.
In cookie we need to maintain the access timestamp on similar lines of access time of file.

Here we have session.serialize_handler as php_serialize to use serialize() and unserialize() for session encoded data.

<?php
    public function updateTimestamp($sessionId, $sessionData)
    {
        $sessionDataArr = unserialize($sessionData);
        $sessionDataArr['_TS_'] = $this->currentTimestamp;
        $sessionData = serialize($sessionDataArr);

        $cookieData = $this->encryptData($sessionData);
        if (strlen($cookieData) > 4096) {
            ob_end_clean();
            die('Session data length exceeds max 4 kilobytes (KB) supported per Cookie');
        }

        return setcookie(
            $name = $this->sessionDataName,
            $value = $cookieData,
            $options = [
                'expires' => 0,
                'path' => '/',
                'domain' => '',
                'secure' => ((strpos($_SERVER['HTTP_HOST'], 'localhost') === false) ? true : false),
                'httponly' => true,
                'samesite' => 'Lax'
            ]
        );
    }
?>
ohcc на 163 dot com
пред 6 години
'validateId' is called after 'open' and before 'read' to validate the session id provided by the client, as 'open' -> 'validateId' -> 'read' -> 'write' -> 'close' are called in sequence.

If 'validateId' returns false, a new session id will be generated, the session cookie will also be updated afterwards.
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.