定义和用法
会话或会话处理是一种使数据跨 Web 应用程序的各个页面可用的方法。 HTTP 标头决定了客户端如何缓存页面内容。您可以使用缓存限制器定义发送到客户端的缓存控制 HTTP 标头。
session_cache_limiter() 函数用于获取或设置当前会话的缓存限制器。
用法
session_cache_limiter([$cache_limiter]);
参数
Sr.No | 参数及说明 |
---|---|
1 |
cache_limiter (Optional) 这是一个表示缓存限制器类型的字符串值,它可以是以下之一 -
|
返回值
此函数返回一个表示创建的会话 ID 的整数值。
PHP版本
这个函数最初是在 PHP 版本 4 中引入的,并且适用于所有后续版本。
例子1
下面的例子演示了session_cache_limiter()函数。
<html>
<head>
<title>Setting up a PHP session</title>
</head>
<body>
<?php
//Retrieving the cache limiter
$limiter = session_cache_limiter();
print("Cache limiter:".$limiter);
?>
</body>
</html>
执行上述 html 文件将显示以下消息 -
Cache limiter:nocache
例子2
下面是这个函数的另一个例子,在这里我们有来自同一个会话中同一个应用程序的两个页面。
session_page1.htm
<?php
if(isset($_POST['SubmitButton'])){
//Setting the cache limiter
session_cache_limiter('public');
session_start();
$_SESSION['name'] = $_POST['name'];
$_SESSION['age'] = $_POST['age'];
}
?>
<html>
<body>
<form action="#" method="post">
<br>
<label for="fname">Enter the values click Submit and click on Next</label>
<br><br><label for="fname">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="lname">Age:</label>
<input type="text" id="age" name="age"><br><br>
<input type="submit" name="SubmitButton"/>
<?php echo '<br><br /><a href="session_page2.htm">Next</a>'; ?>
</form>
</body>
</html>
这将产生以下输出 -
点击时Next执行以下文件。
session_page2.htm
<html>
<head>
<title>Second Page</title>
</head>
<body>
<?php
//Session started
session_start();
//Retrieving the cache limiter
$limiter = session_cache_limiter();
print("Cache limiter:".$limiter);
echo "<br>";
print_r($_SESSION);
?>
</body>
</html>
这将产生以下输出 -
Cache limiter:nocache Array ( [name] => krishna [age] => 30 )
例子3
您可以使用此函数设置缓存限制器,如下所示 -
<html>
<head>
<title>Setting up a PHP session</title>
</head>
<body>
<?php
//Setting the cache limiter
session_cache_limiter('public');
//Retrieving the cache limiter
$limiter = session_cache_limiter();
print("Cache limiter:".$limiter);
?>
</body>
</html>
执行上述 html 文件将显示以下消息 -
Cache limiter:public
相关用法
- PHP session_cache_expire()用法及代码示例
- PHP session_commit()用法及代码示例
- PHP session_create_id()用法及代码示例
- PHP session_gc()用法及代码示例
- PHP session_regenerate_id()用法及代码示例
- PHP session_destroy()用法及代码示例
- PHP session_reset()用法及代码示例
- PHP session_unset() vs session_destroy()用法及代码示例
- PHP session_register_shutdown()用法及代码示例
- PHP session_id()用法及代码示例
- PHP session_start()用法及代码示例
- PHP session_status()用法及代码示例
- PHP session_name()用法及代码示例
- PHP session_set_save_handler()用法及代码示例
- PHP session_save_path()用法及代码示例
- PHP session_set_cookie_params()用法及代码示例
- PHP session_abort()用法及代码示例
- PHP session_decode()用法及代码示例
- PHP session_write_close()用法及代码示例
- PHP session_unset()用法及代码示例
注:本文由纯净天空筛选整理自 PHP - session_cache_limiter() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。