php 读取空cookie,PHP读取cookie文件

我找不到代码来满足

仅限http

现在相当流行的cookie记录-例如

http://www.google.com/

. HttpOnly cookie只能由浏览器读取,并且对所有客户端脚本(如java脚本)保持隐藏状态。您可以找到更多有关HttpOnly cookies的详细信息

here

.

忽略Netscape cookie文件中这些cookie的格式,将导致错误的解析。这些记录的前缀是“#HttpOnly”字符串。

我们还应该为几乎所有应用程序“urldecode”参数名及其值。

以下函数是

Majid Fouladpour

Philip Norton

它只考虑HttpOnly cookies并返回数组中具有其属性的所有cookies:

/**

* Extract any cookies found from the cookie file. This function expects to get

* a string containing the contents of the cookie file which it will then

* attempt to extract and return any cookies found within.

*

* @param string $string The contents of the cookie file.

*

* @return array The array of cookies as extracted from the string.

*

*/

function extractCookies($string) {

$lines = explode(PHP_EOL, $string);

foreach ($lines as $line) {

$cookie = array();

// detect httponly cookies and remove #HttpOnly prefix

if (substr($line, 0, 10) == '#HttpOnly_') {

$line = substr($line, 10);

$cookie['httponly'] = true;

} else {

$cookie['httponly'] = false;

}

// we only care for valid cookie def lines

if( strlen( $line ) > 0 && $line[0] != '#' && substr_count($line, "\t") == 6) {

// get tokens in an array

$tokens = explode("\t", $line);

// trim the tokens

$tokens = array_map('trim', $tokens);

// Extract the data

$cookie['domain'] = $tokens[0]; // The domain that created AND can read the variable.

$cookie['flag'] = $tokens[1]; // A TRUE/FALSE value indicating if all machines within a given domain can access the variable.

$cookie['path'] = $tokens[2]; // The path within the domain that the variable is valid for.

$cookie['secure'] = $tokens[3]; // A TRUE/FALSE value indicating if a secure connection with the domain is needed to access the variable.

$cookie['expiration-epoch'] = $tokens[4]; // The UNIX time that the variable will expire on.

$cookie['name'] = urldecode($tokens[5]); // The name of the variable.

$cookie['value'] = urldecode($tokens[6]); // The value of the variable.

// Convert date to a readable format

$cookie['expiration'] = date('Y-m-d h:i:s', $tokens[4]);

// Record the cookie.

$cookies[] = $cookie;

}

}

return $cookies;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值