MENU

Moleft专用函数库(五) - 从响应头中提取Cookie

• August 31, 2021 • 代码

函数说明

利用正则表达式从Curl响应头中获取Set-Cookie的内容,懂得自然懂

此处内容需要评论回复后方可阅读

使用示例

<?php
$header = <<<EOF
HTTP/1.1 200 OK
Server: Tengine
Date: Tue, 31 Aug 2021 14:51:14 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 45
Connection: keep-alive
Set-Cookie: JSESSIONID=48A4257DBCEA2E9B76E116BA913114CA; Path=/; HttpOnly
Set-Cookie: lv=2; Domain=.chaoxing.com; Expires=Thu, 30-Sep-2021 14:51:14 GMT; Path=/
Set-Cookie: fid=1619; Domain=.chaoxing.com; Expires=Thu, 30-Sep-2021 14:51:14 GMT; Path=/
Set-Cookie: _uid=154982959; Domain=.chaoxing.com; Expires=Thu, 30-Sep-2021 14:51:14 GMT; Path=/
Set-Cookie: uf=b2d2c93beefa90dceea3c95dda94cdc00123b53c040590ba299b772214c809c58bf65abbd4c55c90500603c0fa2bd44b913b662843f1f4ad6d92e371d7fdf6443b938441de6193ed102289339c6dea125558ebfe920d455c3ad9647fd48a5737cdf3e8140a85141b; Domain=.chaoxing.com; Expires=Thu, 30-Sep-2021 14:51:14 GMT; Path=/
Set-Cookie: _d=1630421474065; Domain=.chaoxing.com; Expires=Thu, 30-Sep-2021 14:51:14 GMT; Path=/
Set-Cookie: UID=154982959; Domain=.chaoxing.com; Expires=Thu, 30-Sep-2021 14:51:14 GMT; Path=/
Set-Cookie: vc=A2A5F4EB9D286F1CFF041FBD5586301E; Domain=.chaoxing.com; Expires=Thu, 30-Sep-2021 14:51:14 GMT; Path=/; HttpOnly
Set-Cookie: vc2=90A2890B9BA7075FBEEC4A2C0A37408D; Domain=.chaoxing.com; Expires=Thu, 30-Sep-2021 14:51:14 GMT; Path=/; HttpOnly
Set-Cookie: vc3=PtcThQ83luT2yII0pOKXhZqXKG4Hos5sNovInS%2Bh1HgWek1l9jEWHHlq5zm71T4C3S%2BWjLesZ2q0f8SBR66MTNKrctnrQ%2FOxoUI8eRJEK1o%2FDs2iykW9sTf1KVuKCeiS4rlRM7dtGo5YEEptsRn9nZy8YeL3ravuuO5LEWlgQlI%3D934fc28957b2c2ef46257a1d0028bf03; Domain=.chaoxing.com; Expires=Thu, 30-Sep-2021 14:51:14 GMT; Path=/; HttpOnly
Set-Cookie: xxtenc=03a365813a2ee579cc07b46e93f574ec; Domain=.chaoxing.com; Expires=Thu, 30-Sep-2021 14:51:14 GMT; Path=/
Set-Cookie: DSSTASH_LOG=C_38-UN_1652-US_154982959-T_1630421474067; Domain=.chaoxing.com; Expires=Thu, 30-Sep-2021 14:51:14 GMT; Path=/
Set-Cookie: route=2751c02f853f6479988f0b3d8a5cb9ce;Path=/
EOF;
echo get_cookie($header);

PS

请忽略头图,我真的懒得上传了

Archives QR Code
QR Code for this page
Tipping QR Code