惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
罗磊的独立博客
H
Help Net Security
L
LangChain Blog
T
Threat Research - Cisco Blogs
量子位
S
Securelist
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
The Hacker News
The Hacker News
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
T
Threatpost
Security Latest
Security Latest
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
F
Full Disclosure
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Heimdal Security Blog
J
Java Code Geeks
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog RSS Feed
月光博客
月光博客
C
Cisco Blogs
V
Visual Studio Blog
D
DataBreaches.Net
H
Hacker News: Front Page
博客园 - 叶小钗
N
News and Events Feed by Topic
爱范儿
爱范儿
A
Arctic Wolf

个人技术分享

GPT指令详细资料 – 个人技术分享 php操作cookie 转换数组形式,可取某一个值 – 个人技术分享 php 操作cookie值 – 个人技术分享 js 引入vconsole – 个人技术分享 fastadmin appendfieldlist 用法 – 个人技术分享 PHP 转到 Go – 个人技术分享 PHP使用无头浏览器如何帮助数据提取和抓取 – 个人技术分享 解决移动设备上的所有浏览器顶部都有地址栏,导致高度问题 – 个人技术分享 Python框架 Flask和Django – 区别 – 个人技术分享 PHP To Go 转型手记 – 个人技术分享 真正的50行css代码实现响应式“瀑布流”布局 – 个人技术分享
php操作cookie字符串,替换对应值 – 个人技术分享
hanhanjun888 · 2024-11-21 · via 个人技术分享
if (!function_exists('ckStrReplace')) {
    function ckStrReplace($cookieValue,$replacements)
    {
        if(empty($cookieValue)) return '';
        if(empty($replacements) || !is_array($replacements)) return '';
        // 第一步:将 cookie 字符串拆分为键值对数组
        $cookiePairs = explode(';', $cookieValue);

        // 创建一个关联数组来存储键值对
        $cookieArray = [];
        foreach ($cookiePairs as $pair) {
            $pair = trim($pair); // 去除多余的空格
            if ($pair) {
                list($key, $value) = explode('=', $pair, 2);
                $cookieArray[$key] = $value;
            }
        }

        // 第二步:根据 replacements 数组更新或者添加相应的值
        foreach ($replacements as $key => $newValue) {
            // 如果数组中有这个键,进行替换
            $cookieArray[$key] = $newValue;
        }

        // 第三步:重新组装成 cookie 字符串
        $newCookieValue = '';
        foreach ($cookieArray as $key => $value) {
            $newCookieValue .= $key . '=' . $value . '; ';
        }

        // 去掉最后的多余分号和空格
        return rtrim($newCookieValue, '; ');
    }
}
  • 将原始字符串中的unb和cookie2的值替换
$str = 'cna=Z10vHxyLLhkCAXPgqFaTMN9A; t=0dfd9e12691b5e686d8e406981bc179f; cookie2=113f243906b3776465e8fc246291d43d; xlly_s=1; _samesite_flag_=true; _tb_token_=548dd75bd1b39; unb=2209368547703; _hvn_lgc_=77; mtop_partitioned_detect=1; _m_h5_tk=518ab9b7ade30d1634c92f423962eb36_1729138819303; _m_h5_tk_enc=548aa63b41127caaeb4e9bc65e796a49; sdkSilent=1729216940928; sgcookie=E100MANykuWklerydA%2BMl9VIKBDu93fi6%2FAkc52GgwunEqZm9s%2F4QR3w70efJdK0OjoqaSSsURjd8rmp0UbOxRuxqtfyCuinoz28cswnbcjUUfk%3D; csg=96db0be1; havana_lgc2_77=eyJoaWQiOjIyMDkzNjg1NDc3MDMsInNnIjoiM2I1OTA0MDEzYTljZTcwZTRkZDkwYTQ1YzkzYjgxYzEiLCJzaXRlIjo3NywidG9rZW4iOiIxcEprcmNFY3FXa3l3U1RnY2hhT1U0dyJ9; havana_lgc_exp=1731722711974; isg=BHd3EOiN3F5lmFlq1jMGY7UyBm3BPEuetKiDGckl5cateJK60QzK7iOTWtgmkCMW; tfstk=gtErVp23SDVj2CSshxnEQC-n2_n-D0f1tkGIKJ2nFbcoAahntJFxdHw3VWPU_7-7OJf8TklmM2aWVWNeT7NjZ3wSNSl31SZI-6n7gSa0k_C-O8MUGr4Aw_EUpHk3KWB-OTQbe8nKx11_YGw8eWEySDXjrIXnLv1_7crXm8nKx19XxNsae50nOCBExtomdYJox2cl3jDsi3DHqvAc3vhmx30nrqAmevkk-vV3ntkKiXDL382H0AglCB0NDGfWA4cgEj-HbdHrrewWRh-a0Yuzx8cVL9rqU4lilG5xelygElHUvOYETzzuNxFFbso0gy2nuo1kfXaaCk3Uq9pS9zMtqYPhjFG0u-q-5-pPI-ija-DTu1--VRz0VqEGG3FUC7rE57scEWnoKW3TA1K-ZJ2TXPiNYFogg-qt-kCvvXabKko8sst492jrHBHmRXqLzBYnrxHq1tW4O4UiIC35k2YpJqmt3f6SFeLKrWMq1TgBJe3mtxl1Fw5..';
        dump($str);
        $newStr = ckStrReplace($str,[
            'unb' => '测试',
            'cookie2' => '测试2',
            'x5sec' => 'test2'
        ]);
        dump($newStr);