PHP - Manual手册 - CXLIX Session 会话处理函数 - session use only co

本文围绕PHP展开,重点介绍了Session会话处理函数中session.use_only_cookies,该设定指定是否仅用cookie存放会话ID,启用可防URL传递会话ID攻击。还提供了PHP相关下载资源、手册链接及应用实例等信息技术相关内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

               

   PHP - Manual手册 - CXLIX. Session 会话处理函数 - session.use_only_cookies指定是否在客户端仅仅使用 cookie 来存放会话 ID

   session.use_only_cookies boolean

   session.use_only_cookies 指定是否在客户端仅仅使用 cookie 来存放会话 ID。。启用此设定可以防止有关通过 URL 传递会话 ID 的攻击。此设定是 PHP 4.3.0 添加的。

   [session.use_only_cookies指定是否在客户端仅仅使用 cookie 来存放会话 ID - 文档]

   http://www.php.net/manual/zh/ref.session.php#ini.session.use-only-cookies

   [PHP - 关键词]

php

   [PHP - 相关论坛]

http://php.board.newsmth.net/  http://bbs.pku.edu.cn/, homepage看版  http://forum.csdn.net/SList/PHP/

   [PHP - 下载]

AppServ 2.5.9, http://www.appservnetwork.com/

   Zend Optimizer 3.3.0a, http://www.zend.com/products/zend_optimizer

   phpMyAdmin 2.11.2, http://www.phpmyadmin.net/home_page/index.php

   Zend Core 2.5.0, http://www.zend.com/products/zend_core

   Zend Platform 3.0.3, http://www.zend.com/products/zend_platform

   PHP 5.2.5, http://www.php.net/releases/5_2_5.php

   Zend Studio 5.5, http://www.zend.com/products/zend_studio

   Zend Guard 5.0, http://www.zend.com/products/zend_guard

   [PHP - Manual手册]

   PHP: PHP 类型比较表 - Manual: http://www.php.net/manual/zh/types.comparisons.php#id9240444

   PHP: 变量范围 - Manual:, http://www.php.net/manual/zh/language.variables.scope.php#language.variables.scope.references

   PHP - PHP 的命令行模式 - CLI 专用常量, http://www.php.net/manual/zh/features.commandline.php#id2715646

   PHP - token_get_all用于解析PHP源代码, http://www.php.net/manual/zh/function.token-get-all.php

   PHP - reset — 将数组的内部指针指向第一个单元, http://www.php.net/manual/zh/function.reset.php

   PHP - serialize — 产生一个可存储的值的表示, http://www.php.net/manual/zh/function.serialize.php

   PHP: 魔术常量 - Manual:, http://www.php.net/manual/zh/language.constants.predefined.php

   PHP: SOAP Functions - soap.wsdl_cache_enabled, http://cn.php.net/manual/zh/ref.soap.php#ini.soap.wsdl-cache-enabled

   字符串转换为数值, http://www.php.net/manual/zh/language.types.string.php#language.types.string.conversion

   Class Abstraction类抽象, http://www.php.net/manual/zh/language.oop5.abstract.php

foreach遍历数组, http://www.php.net/manual/zh/control-structures.foreach.php

   SOAP configuration options missing documentation文档中丢失SOAP配置选项, http://bugs.php.net/bug.php?id=38644

   PHP 的命令行模式, http://www.php.net/manual/zh/features.commandline.php

   位运算符, http://www.php.net/manual/zh/language.operators.bitwise.php#id2665181

   file_exists检查文件或目录是否存在, http://www.php.net/manual/zh/function.file-exists.php

  

   is_file判断给定文件名是否为一个正常的文件, http://www.php.net/manual/zh/function.is-file.php   

   settype设置变量的类型, http://cn.php.net/manual/zh/function.settype.php#function.settype

   is_numeric检测变量是否为数字或数字字符串, http://www.php.net/manual/zh/function.is-numeric.php

   ksort对数组按照键名排序, http://www.php.net/manual/zh/function.ksort.php

   [PHP - Manual手册 - 下载]

http://www.php.net/download-docs.php

   [PHP - Manual手册 - 第19章 类与对象(PHP 5)]

Object cloning对象克隆, http://www.php.net/manual/zh/language.oop5.cloning.php

   [PHP - Manual手册 - 第20章 异常处理]

   概述, http://www.php.net/manual/zh/language.exceptions.php

   用异常处理php改进流程

   [PHP - Manual手册 - 第21章 引用的解释]

   引用返回, http://www.php.net/manual/zh/language.references.return.php

   [PHP - Manual手册 - V. Array 数组函数]

计算数组的交集, http://www.php.net/manual/zh/function.array-intersect.php

   array_merge合并一个或多个数组, http://www.php.net/manual/zh/function.array-merge.php

   [PHP - Manual手册 - XVIII. CURL, 客户端URL库函数]

   概述, http://www.php.net/manual/zh/ref.curl.php

curl_setopt设置cURL传输的选项, http://www.php.net/manual/zh/function.curl-setopt.php#function.curl-setopt

   [PHP - Manual手册 - XXII. Date/Time 日期/时间函数]

date格式化一个本地时间/日期, http://www.php.net/manual/zh/function.date.php

   [PHP - Manual手册 - XXXIII. Error Handling and Logging Functions错误处理和日志函数]

概述, http://www.php.net/manual/zh/ref.errorfunc.php

   [PHP - Manual手册 - XLVII. Function Handling Functions函数管理函数]

   register_shutdown_function注册一个脚本结束时调用的函数, http://www.php.net/manual/zh/function.register-shutdown-function.php

   [PHP - Manual手册 - XC. Miscellaneous Functions杂项函数]

   sleep延迟执行, http://www.php.net/manual/zh/ref.misc.php

   uniqid生成唯一ID, http://www.php.net/manual/zh/function.uniqid.php

   [PHP - Manual手册 - XCVIII. MySQL 函数] 

   mysql_real_escape_string转义SQL语句中使用的字符串中的特殊字符,并考虑到连接的当前字符集, http://www.php.net/manual/zh/function.mysql-real-escape-string.php    

   [PHP - Manual手册 - CXXVII. PostgreSQL 数据库函数]

pg_insert将数组插入到表中, http://www.php.net/manual/zh/index.php

   [PHP - Manual手册 - CXXX. Program Execution Functions程序调用函数]

   proc_open执行命令并打开用于输入输出的文件指针, http://www.php.net/manual/zh/function.proc-open.php

   [PHP - Manual手册 - CXLIX. Session 会话处理函数]

session.save_path 定义了传递给存储处理器的参数, http://www.php.net/manual/zh/ref.session.php#ini.session.save-path

session.use_only_cookies指定是否在客户端仅仅使用 cookie 来存放会话 ID, http://www.php.net/manual/zh/ref.session.php#ini.session.use-only-cookies

   [PHP - Manual手册 - CLXI. String 字符串处理函数]

str_pad使用另一个字符串将一个字符串填充到指定长度, http://www.php.net/manual/zh/function.str-pad.php

   strpos查找一个字符串第一次出现的位置, http://www.php.net/manual/zh/function.strpos.php

   substr返回字符串中的一部分, http://www.php.net/manual/zh/function.substr.php

   [PHP - Manual手册 - CLXVI. Tidy Functions - Tidy函数]

概述, http://www.php.net/manual/zh/ref.tidy.php

   [PHP - Manual手册 - CLXIX. URL 函数]

概述, http://www.php.net/manual/zh/ref.url.php

   [PHP - Manual手册 - 附录 H. php.ini 配置选项]

register_globals 决定是否将 EGPCS(Environment,GET,POST,Cookie,Server)变量注册为全局变量, http://www.php.net/manual/zh/ini.core.php#ini.register-globals

   short_open_tag决定是否允许使用PHP代码开始标志的缩写形式, http://www.php.net/manual/zh/ini.core.php#ini.short-open-tag

   [PHP - Manual手册 - 附录 L. 保留字列表]

   服务器变量:$_SERVER, http://www.php.net/manual/zh/reserved.variables.php#reserved.variables.server

   [PHP - 应用实例] 

   语法着色, php.exe -s "%1" > "%1.html" 

   移除SimpleXML对象中的子对象

           

分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

### 如何在 Requests-HTML 中实现 Cookie 注入或管理 Requests-HTML 是一个功能强大的库,用于解析 HTML 和执行 JavaScript 渲染页面。它基于 Pyppeteer 或 Selenium 提供的功能扩展了标准 `requests` 库的能力。尽管其主要目标不是专门处理 Cookies,但它仍然可以通过底层接口来管理和注入 Cookies。 以下是关于如何在 Requests-HTML 中实现 Cookie 的注入和管理的具体方法: #### 1. 使用 `session.cookies.update()` 方法设置自定义 Cookies 通过创建一个会话对象并更新其中的 Cookies 字典,可以轻松地向请求中注入自定义 Cookies。这种方法类似于标准 `requests.Session` 对象的操作方式[^1]。 ```python from requests_html import HTMLSession # 创建一个新的会话实例 session = HTMLSession() # 定义要注入的Cookies字典 custom_cookies = { 'example_cookie': 'value', 'another_example': 'test_value' } # 更新会话中的Cookies session.cookies.update(custom_cookies) # 发送带有自定义Cookies的GET请求 response = session.get('https://httpbin.org/cookies') print(response.text) ``` 上述代码展示了如何利用 `update()` 函数将指定的 Cookies 添加到会话中,并自动将其应用于后续的所有请求中。 #### 2. 手动控制每条请求的 Cookies 如果不想让特定的 Cookies 自动附加于未来的请求,则可以在每次调用时单独传递它们。这可通过 `get()` 或其他 HTTP 请求函数的参数完成。 ```python url = 'https://httpbin.org/cookies' # 设置单次使用的Cookies manual_cookies = {'single_use_cookie': 'temporary'} # 进行一次性的带Cookie请求 response = session.get(url, cookies=manual_cookies) print(response.text) ``` 此片段说明了即使启用了全局会话级配置的情况下,也可以针对某些特殊场景禁用默认行为并通过显式的参数覆盖之。 #### 3. 删除已存在的 Cookies 当不再希望某个网站关联任何存储下来的Cookies数据时,可采用如下手段清除掉这些记录: ```python # 移除名为'example_cookie'的一个具体项 if 'example_cookie' in session.cookies: del session.cookies['example_cookie'] # 或者完全清空整个集合 session.cookies.clear() ``` 以上脚本演示了两种不同的删除策略——既可以逐个移除选定的目标键名;也能一键抹去全部现存项目。 --- ### 总结 综上所述,在 Requests-HTML 中进行 Cookie 处理并不复杂。无论是批量导入还是精细化调整都可以借助内置工具达成目的。值得注意的是,默认情况下程序会对返回结果里的 Set-Cookie 响应头做相应解读并将新获取的信息保存下来以便下次访问相同站点时重用。 如果需要关闭这一特性则需手动干预如前所述那样设定 `configure cookies=None`.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值