Second Page

session_cache_expire

session_cache_expire() возвращает текущее значение настройки session.cache_expire .

Срок действия сбрасывается до значения по умолчанию (180), хранящегося в session.cache_expire во время запроса. Таким образом, нужно вызывать session_cache_expire() для каждого запроса (и до вызова session_start() ).

Список параметров

Если value задан и не равен null , текущее время жизни заменяется на value .

Замечание: Настройка value имеет значение только, если для session.cache_limiter установлено значение, отличное от nocache .

Возвращаемые значения

Возвращает текущую настройку session.cache_expire . Возвращаемое значение должно рассматриваться в минутах, по умолчанию — 180. В случае, если изменить значение не удалось, возвращается false .

Список изменений

Примеры

Пример #1 Пример использования session_cache_expire()

/* установить ограничитель кеша на ‘private’ */

session_cache_limiter ( ‘private’ );
$cache_limiter = session_cache_limiter ();

/* установить время жизни на 30 минут */
session_cache_expire ( 30 );
$cache_expire = session_cache_expire ();

echo «Ограничитель кеша теперь равен $cache_limiter
» ;
echo «Закешированные страницы сессии истекают через $cache_expire минут» ;
?>

Смотрите также

User Contributed Notes 3 notes

The manual probably doesn’t stress this enough:

** This has nothing to do with lifetime of a session **

Whatever you set this setting to, it won’t change how long sessions live on your server.

This only changes HTTP cache expiration time (Expires: and Cache-Control: max-age headers), which advise browser for how long it can keep pages cached in user’s cache without having to reload them from the server.

I’ve encountered the same problem of loosing focus when using IE and a javascript window.location.refresh/replace().

After fusing around I found that a works without move the focus on the parent frame’s form. The down side is loading up the browser history and an annoying ‘click’ in IE on the page load.

Just to make things clear. If session.cache_limiter is set to private the following header will be sent in HTTP response:

Cache-Control private, max-age=10800, pre-check=10800

Where 10800 is the amount of seconds — default value of 180 minutes set by session.cache_expire which you are enabled to change with session_cache_expire() on run-time

  • Функции для работы с сессиями
    • session_​abort
    • session_​cache_​expire
    • session_​cache_​limiter
    • session_​commit
    • session_​create_​id
    • session_​decode
    • session_​destroy
    • session_​encode
    • session_​gc
    • session_​get_​cookie_​params
    • session_​id
    • session_​module_​name
    • session_​name
    • session_​regenerate_​id
    • session_​register_​shutdown
    • session_​reset
    • session_​save_​path
    • session_​set_​cookie_​params
    • session_​set_​save_​handler
    • session_​start
    • session_​status
    • session_​unset
    • session_​write_​close

    Источник

    PHP — session_cache_expire() Function

    Sessions or session handling is a way to make the data available across various pages of a web application. The session_cache_expire() function is used to get the current cache expire.

    Syntax

    session_cache_expire([$new_cache_expire]);

    Parameters

    new_cache_expire (Optional)

    This is an integer value representing the new cache expire value.

    Return Values

    This function returns the current cache expire value.

    PHP Version

    This function was first introduced in PHP Version 4 and works in all the later versions.

    Example 1

    Following example demonstrates the usage of the session_cache_expire() function.

    One executing the above html file it will display the following message −

    The number in the message keeps changing based on the number of times you refresh the page without closing the browser. For example, if you refresh 10 times, then the same page displays the following message

    You have visited this page 16 times in this session.

    Example 2

    Following is another example of this function, in here we have two pages from the same application in the same session.

     ?>   








    Next'; ?>

    This will produce the following output −

    Session Start

    On clicking on Next the following file is executed.

        "; print_r($_SESSION); ?>  

    This will produce the following output −

    Cache Expire: 180 Array ( [name] => krishna [age] => 30 )

    Example 3

    You can set session expire using this function as shown below −

    One executing the above html file it will display the following message −

    Источник

    Функции для работы с сессиями

    Be aware of the fact that absolute URLs are NOT automatically rewritten to contain the SID.

    Of course, it says so in the documentation (‘Passing the Session Id’) and of course it makes perfectly sense to have that restriction, but here’s what happened to me:
    I have been using sessions for quite a while without problems. When I used a global configuration file to be included in all my scripts, it contained a line like this:

    which was used to make sure that all automatically generated links had the right prefix (just like $cfg[‘PmaAbsoluteUri’] works in phpMyAdmin). After introducing that variable, no link would pass the SID anymore, causing every script to return to the login page. It took me hours (!!) to recognize that this wasn’t a bug in my code or some misconfiguration in php.ini and then still some more time to find out what it was. The above restriction had completely slipped from my mind (if it ever was there. )

    Skipping the ‘http:’ did the job.

    OK, it was my own mistake, of course, but it just shows you how easily one can sabotage his own work for hours. Just don’t do it 😉

    Sessions and browser’s tabs

    May you have noticed when you open your website in two or more tabs in Firefox, Opera, IE 7.0 or use ‘Control+N’ in IE 6.0 to open a new window, it is using the same cookie or is passing the same session id, so the another tab is just a copy of the previous tab. What you do in one will affect the another and vice-versa. Even if you open Firefox again, it will use the same cookie of the previous session. But that is not what you need mostly of time, specially when you want to copy information from one place to another in your web application. This occurs because the default session name is «PHPSESSID» and all tabs will use it. There is a workaround and it rely only on changing the session’s name.

    Put these lines in the top of your main script (the script that call the subscripts) or on top of each script you have:

    if( version_compare ( phpversion (), ‘4.3.0’ )>= 0 ) <
    if(! ereg ( ‘^SESS5+$’ , $_REQUEST [ ‘SESSION_NAME’ ])) <
    $_REQUEST [ ‘SESSION_NAME’ ]= ‘SESS’ . uniqid ( » );
    >
    output_add_rewrite_var ( ‘SESSION_NAME’ , $_REQUEST [ ‘SESSION_NAME’ ]);
    session_name ( $_REQUEST [ ‘SESSION_NAME’ ]);
    >
    ?>

    How it works:

    First we compare if the PHP version is at least 4.3.0 (the function output_add_rewrite_var() is not available before this release).

    After we check if the SESSION_NAME element in $_REQUEST array is a valid string in the format «SESSIONxxxxx», where xxxxx is an unique id, generated by the script. If SESSION_NAME is not valid (ie. not set yet), we set a value to it.

    uniqid(») will generate an unique id for a new session name. It don’t need to be too strong like uniqid(rand(),TRUE), because all security rely in the session id, not in the session name. We only need here a different id for each session we open. Even getmypid() is enough to be used for this, but I don’t know if this may post a treat to the web server. I don’t think so.

    output_add_rewrite_var() will add automatically a pair of ‘SESSION_NAME=SESSxxxxx’ to each link and web form in your website. But to work properly, you will need to add it manually to any header(‘location’) and Javascript code you have, like this:

    The last function, session_name() will define the name of the actual session that the script will use.

    So, every link, form, header() and Javascript code will forward the SESSION_NAME value to the next script and it will know which is the session it must use. If none is given, it will generate a new one (and so, create a new session to a new tab).

    May you are asking why not use a cookie to pass the SESSION_NAME along with the session id instead. Well, the problem with cookie is that all tabs will share the same cookie to do it, and the sessions will mix anyway. Cookies will work partially if you set them in different paths and each cookie will be available in their own directories. But this will not make sessions in each tab completly separated from each other. Passing the session name through URL via GET and POST is the best way, I think.

    Источник

    Читайте также:  HTML Select Country Phone Code List with Flags
Оцените статью